Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id AD657200BD1 for ; Mon, 28 Nov 2016 09:46:28 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id ABFA1160B0D; Mon, 28 Nov 2016 08:46:28 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id AF9C7160B06 for ; Mon, 28 Nov 2016 09:46:25 +0100 (CET) Received: (qmail 91175 invoked by uid 500); 28 Nov 2016 08:46:24 -0000 Mailing-List: contact commits-help@eagle.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@eagle.incubator.apache.org Delivered-To: mailing list commits@eagle.incubator.apache.org Received: (qmail 91166 invoked by uid 99); 28 Nov 2016 08:46:24 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 28 Nov 2016 08:46:24 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id 40BE7180256 for ; Mon, 28 Nov 2016 08:46:24 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -4.718 X-Spam-Level: X-Spam-Status: No, score=-4.718 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, KAM_MXURI=1.5, RCVD_IN_DNSWL_HI=-5, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RP_MATCHES_RCVD=-2.999, URIBL_BLOCKED=0.001] autolearn=disabled Received: from mx1-lw-us.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id U2TJaMGzke8w for ; Mon, 28 Nov 2016 08:46:13 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx1-lw-us.apache.org (ASF Mail Server at mx1-lw-us.apache.org) with SMTP id B357C5F246 for ; Mon, 28 Nov 2016 08:46:12 +0000 (UTC) Received: (qmail 91063 invoked by uid 99); 28 Nov 2016 08:46:12 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 28 Nov 2016 08:46:12 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id C87C9E008F; Mon, 28 Nov 2016 08:46:11 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: jinhuwu@apache.org To: commits@eagle.incubator.apache.org Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: incubator-eagle git commit: [EAGLE-801] Add unit test for eagle-core module Date: Mon, 28 Nov 2016 08:46:11 +0000 (UTC) archived-at: Mon, 28 Nov 2016 08:46:28 -0000 Repository: incubator-eagle Updated Branches: refs/heads/master 4d4d8c0ea -> 7976858ee [EAGLE-801] Add unit test for eagle-core module EAGLE-801 Add unit test for eagle-core module - Add unit test for eagle-core module. https://issues.apache.org/jira/browse/EAGLE-801 Author: chitin Author: Lingang Deng Closes #685 from chitin/EAGLE-801. Project: http://git-wip-us.apache.org/repos/asf/incubator-eagle/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-eagle/commit/7976858e Tree: http://git-wip-us.apache.org/repos/asf/incubator-eagle/tree/7976858e Diff: http://git-wip-us.apache.org/repos/asf/incubator-eagle/diff/7976858e Branch: refs/heads/master Commit: 7976858ee068ca4a85d67f70f7bf574f3e75115f Parents: 4d4d8c0 Author: chitin Authored: Mon Nov 28 16:46:03 2016 +0800 Committer: wujinhu Committed: Mon Nov 28 16:46:03 2016 +0800 ---------------------------------------------------------------------- eagle-core/eagle-app/eagle-app-base/pom.xml | 12 + .../app/service/ApplicationActionTest.java | 58 +++++ ...estApplicationHealthCheckEmailPublisher.java | 64 +++++ .../TestApplicationHealthCheckServiceImpl.java | 101 ++++++++ .../TestApplicationManagementServiceImpl.java | 181 +++++++++++++++ .../org/apache/eagle/common/TestBase64.java | 32 +++ .../eagle/common/TestEagleExceptionWrapper.java | 32 +++ .../eagle/common/TestSerializableUtils.java | 1 - .../eagle/common/config/TestConfigParser.java | 36 +++ .../eagle-metadata/eagle-metadata-base/pom.xml | 4 + .../eagle/metadata/model/TestConfiguration.java | 67 ++++++ .../metadata/persistence/MetadataStoreTest.java | 28 +++ .../TestMetadataStoreModuleFactory.java | 33 +++ .../TestApplicationEntityServiceMemoryImpl.java | 231 +++++++++++++++++++ .../TestSiteEntityServiceMemoryImpl.java | 97 ++++++++ .../src/test/resources/application-test.conf | 31 +++ .../src/test/resources/application-test.xml | 17 ++ .../ApplicationEntityServiceJDBCImplTest.java | 66 ++++++ .../src/test/resources/application.conf | 6 +- 19 files changed, 1095 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/7976858e/eagle-core/eagle-app/eagle-app-base/pom.xml ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-app/eagle-app-base/pom.xml b/eagle-core/eagle-app/eagle-app-base/pom.xml index 5e55239..a5e295e 100644 --- a/eagle-core/eagle-app/eagle-app-base/pom.xml +++ b/eagle-core/eagle-app/eagle-app-base/pom.xml @@ -113,5 +113,17 @@ + + org.powermock + powermock-module-junit4 + ${powermock.version} + test + + + org.powermock + powermock-api-mockito + ${powermock.version} + test + \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/7976858e/eagle-core/eagle-app/eagle-app-base/src/test/java/org/apache/eagle/app/service/ApplicationActionTest.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-app/eagle-app-base/src/test/java/org/apache/eagle/app/service/ApplicationActionTest.java b/eagle-core/eagle-app/eagle-app-base/src/test/java/org/apache/eagle/app/service/ApplicationActionTest.java index d076bf7..76bb76a 100644 --- a/eagle-core/eagle-app/eagle-app-base/src/test/java/org/apache/eagle/app/service/ApplicationActionTest.java +++ b/eagle-core/eagle-app/eagle-app-base/src/test/java/org/apache/eagle/app/service/ApplicationActionTest.java @@ -18,10 +18,24 @@ package org.apache.eagle.app.service; import com.typesafe.config.Config; import com.typesafe.config.ConfigFactory; +import org.apache.commons.collections.map.HashedMap; +import org.apache.eagle.alert.engine.coordinator.StreamDefinition; +import org.apache.eagle.alert.metadata.IMetadataDao; +import org.apache.eagle.alert.metadata.impl.InMemMetadataDaoImpl; +import org.apache.eagle.alert.metric.MetricConfigs; +import org.apache.eagle.app.Application; +import org.apache.eagle.app.environment.impl.StaticEnvironment; +import org.apache.eagle.metadata.model.ApplicationDesc; +import org.apache.eagle.metadata.model.ApplicationEntity; +import org.apache.eagle.metadata.model.SiteEntity; import org.junit.Assert; import org.junit.Test; +import static org.mockito.Mockito.*; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; +import java.util.Map; public class ApplicationActionTest { /** @@ -45,4 +59,48 @@ public class ApplicationActionTest { Assert.assertEquals("appConfig.withFallback(envConfig): appConfig will override envConfig, envConfig is used as default config", "APP",mergedConfig.getString("SCOPE")); } + + @Test + public void testDoAction() { + Application application = mock(Application.class); + when(application.getEnvironmentType()).thenReturn(StaticEnvironment.class); + SiteEntity siteEntity = new SiteEntity(); + siteEntity.setSiteId("testsiteid"); + siteEntity.setSiteName("testsitename"); + siteEntity.setDescription("testdesc"); + ApplicationDesc applicationDesc = new ApplicationDesc(); + List streamDefinitions = new ArrayList<>(); + StreamDefinition sd = new StreamDefinition(); + sd.setStreamId("streamId"); + sd.setDescription("desc"); + sd.setValidate(true); + sd.setTimeseries(false); + sd.setDataSource("ds1"); + sd.setSiteId("siteId"); + streamDefinitions.add(sd); + applicationDesc.setStreams(streamDefinitions); + applicationDesc.setType("type1"); + ApplicationEntity metadata = new ApplicationEntity(); + metadata.setAppId("appId"); + metadata.setSite(siteEntity); + metadata.setDescriptor(applicationDesc); + metadata.setMode(ApplicationEntity.Mode.LOCAL); + metadata.setJarPath(applicationDesc.getJarPath()); + Map configure = new HashedMap(); + configure.put("a", "b"); + metadata.setConfiguration(configure); + metadata.setContext(configure); + Config serverConfig = ConfigFactory.parseMap(new HashMap(){{ + put("dataSinkConfig.topic", "test_topic"); + put("dataSinkConfig.brokerList", "sandbox.hortonworks.com:6667"); + put(MetricConfigs.METRIC_PREFIX_CONF, "eagle."); + }}); + IMetadataDao alertMetadataService = new InMemMetadataDaoImpl(serverConfig); + ApplicationAction applicationAction = new ApplicationAction(application, metadata, serverConfig, alertMetadataService); + applicationAction.doInstall(); + applicationAction.doUninstall(); + applicationAction.doStart(); + applicationAction.doStop(); + Assert.assertEquals(ApplicationEntity.Status.INITIALIZED, applicationAction.getStatus()); + } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/7976858e/eagle-core/eagle-app/eagle-app-base/src/test/java/org/apache/eagle/app/service/TestApplicationHealthCheckEmailPublisher.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-app/eagle-app-base/src/test/java/org/apache/eagle/app/service/TestApplicationHealthCheckEmailPublisher.java b/eagle-core/eagle-app/eagle-app-base/src/test/java/org/apache/eagle/app/service/TestApplicationHealthCheckEmailPublisher.java new file mode 100644 index 0000000..23de188 --- /dev/null +++ b/eagle-core/eagle-app/eagle-app-base/src/test/java/org/apache/eagle/app/service/TestApplicationHealthCheckEmailPublisher.java @@ -0,0 +1,64 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.eagle.app.service; + +import com.codahale.metrics.health.HealthCheck; +import com.typesafe.config.Config; +import com.typesafe.config.ConfigFactory; +import org.apache.eagle.alert.engine.publisher.email.EagleMailClient; +import org.apache.eagle.app.service.impl.ApplicationHealthCheckEmailPublisher; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; +import static org.mockito.Mockito.*; + +import java.util.HashMap; + +/** + * @Since 11/24/16. + */ +@RunWith(PowerMockRunner.class) +@PrepareForTest({ApplicationHealthCheckEmailPublisher.class}) +public class TestApplicationHealthCheckEmailPublisher { + + @Test + public void testOnUnHealthApplication() throws Exception { + Config config = ConfigFactory.parseMap(new HashMap() { + { + put("mail.smtp.recipients", "recipient@eagle.com"); + put("mail.smtp.sender", "sender@eagle.com"); + put("mail.smtp.subject", "test_subject"); + put("mail.smtp.cc", "cc@eagle.com"); + put("mail.smtp.template", "test_template"); + put("mail.smtp.host", "localhost"); + put("mail.smtp.port", "25"); + put("host", "localhost"); + put("port", "9090"); + } + }); + ApplicationHealthCheckEmailPublisher publisher = new ApplicationHealthCheckEmailPublisher(config); + EagleMailClient client = mock(EagleMailClient.class); + PowerMockito.whenNew(EagleMailClient.class).withAnyArguments().thenReturn(client); + when(client.send(anyString(), anyString(), anyString(), anyString(), anyString(), anyObject(), anyObject())).thenReturn(false, true); + publisher.onUnHealthApplication("appId", new HashMap(){{ + put("appId", HealthCheck.Result.healthy()); + }}); + verify(client, times(2)).send(anyString(), anyString(), anyString(), anyString(), anyString(), anyObject(), anyObject()); + } +} http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/7976858e/eagle-core/eagle-app/eagle-app-base/src/test/java/org/apache/eagle/app/service/TestApplicationHealthCheckServiceImpl.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-app/eagle-app-base/src/test/java/org/apache/eagle/app/service/TestApplicationHealthCheckServiceImpl.java b/eagle-core/eagle-app/eagle-app-base/src/test/java/org/apache/eagle/app/service/TestApplicationHealthCheckServiceImpl.java new file mode 100644 index 0000000..ebb4856 --- /dev/null +++ b/eagle-core/eagle-app/eagle-app-base/src/test/java/org/apache/eagle/app/service/TestApplicationHealthCheckServiceImpl.java @@ -0,0 +1,101 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.eagle.app.service; + +import com.codahale.metrics.health.HealthCheckRegistry; +import com.google.inject.Injector; +import com.typesafe.config.Config; +import com.typesafe.config.ConfigFactory; +import io.dropwizard.setup.Environment; +import org.apache.commons.collections.map.HashedMap; +import org.apache.eagle.app.service.impl.ApplicationHealthCheckServiceImpl; +import org.apache.eagle.app.service.impl.ApplicationProviderServiceImpl; +import org.apache.eagle.metadata.model.ApplicationDesc; +import org.apache.eagle.metadata.model.ApplicationEntity; +import org.apache.eagle.metadata.model.SiteEntity; +import org.apache.eagle.metadata.service.ApplicationEntityService; +import org.junit.Before; +import org.junit.Test; +import org.powermock.reflect.Whitebox; + +import java.util.*; + +import static org.mockito.Mockito.*; + +/** + * @Since 11/24/16. + */ +public class TestApplicationHealthCheckServiceImpl { + + ApplicationProviderService applicationProviderService; + ApplicationEntityService applicationEntityService; + Environment environment; + Config config; + ApplicationHealthCheckServiceImpl applicationHealthCheckService; + + @Before + public void setUp() { + applicationEntityService = mock(ApplicationEntityService.class); + environment = mock(Environment.class); + config = ConfigFactory.parseMap(new HashMap() { + { + put("application.healthCheck.initialDelay", "10000"); + put("application.healthCheck.period", "10000"); + put("application.healthCheck.publisher.publisherImpl", "org.apache.eagle.app.service.impl.ApplicationHealthCheckEmailPublisher"); + put("application.healthCheck.publisher.dailySendHour", "11"); + put("service.timezone", "UTC"); + put("application.provider.loader", "org.apache.eagle.app.service.impl.ApplicationProviderSPILoader"); + } + }); + applicationProviderService = new ApplicationProviderServiceImpl(config); + HealthCheckRegistry healthCheckRegistry = new HealthCheckRegistry(); + when(environment.healthChecks()).thenReturn(healthCheckRegistry); + when(applicationEntityService.findAll()).thenReturn(generateCollections()); + applicationHealthCheckService = new ApplicationHealthCheckServiceImpl(applicationProviderService, applicationEntityService, config); + Injector injector = mock(Injector.class); + Whitebox.setInternalState(applicationHealthCheckService, "currentInjector", injector); + + } + + @Test + public void testInit() throws NoSuchFieldException, IllegalAccessException { + applicationHealthCheckService.init(environment); + applicationHealthCheckService.unregister((ApplicationEntity)((List)generateCollections()).get(0)); + } + + public Collection generateCollections() { + Collection entities = new ArrayList<>(); + SiteEntity siteEntity = new SiteEntity(); + siteEntity.setSiteId("testsiteid"); + siteEntity.setSiteName("testsitename"); + siteEntity.setDescription("testdesc"); + ApplicationDesc applicationDesc = new ApplicationDesc(); + applicationDesc.setType("TEST_APPLICATION"); + ApplicationEntity applicationEntity = new ApplicationEntity(); + applicationEntity.setSite(siteEntity); + applicationEntity.setDescriptor(applicationDesc); + applicationEntity.setMode(ApplicationEntity.Mode.LOCAL); + applicationEntity.setJarPath(applicationDesc.getJarPath()); + Map configure = new HashedMap(); + configure.put("a", "b"); + applicationEntity.setConfiguration(configure); + applicationEntity.setContext(configure); + applicationEntity.setAppId("appId"); + entities.add(applicationEntity); + return entities; + } +} http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/7976858e/eagle-core/eagle-app/eagle-app-base/src/test/java/org/apache/eagle/app/service/TestApplicationManagementServiceImpl.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-app/eagle-app-base/src/test/java/org/apache/eagle/app/service/TestApplicationManagementServiceImpl.java b/eagle-core/eagle-app/eagle-app-base/src/test/java/org/apache/eagle/app/service/TestApplicationManagementServiceImpl.java new file mode 100644 index 0000000..c4b0227 --- /dev/null +++ b/eagle-core/eagle-app/eagle-app-base/src/test/java/org/apache/eagle/app/service/TestApplicationManagementServiceImpl.java @@ -0,0 +1,181 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.eagle.app.service; + +import com.typesafe.config.Config; +import com.typesafe.config.ConfigFactory; +import junit.framework.Assert; +import org.apache.commons.collections.map.HashedMap; +import org.apache.eagle.alert.metadata.IMetadataDao; +import org.apache.eagle.alert.metadata.impl.InMemMetadataDaoImpl; +import org.apache.eagle.app.service.impl.ApplicationHealthCheckServiceImpl; +import org.apache.eagle.app.service.impl.ApplicationManagementServiceImpl; +import org.apache.eagle.app.service.impl.ApplicationProviderServiceImpl; +import org.apache.eagle.metadata.exceptions.ApplicationWrongStatusException; +import org.apache.eagle.metadata.exceptions.EntityNotFoundException; +import org.apache.eagle.metadata.model.ApplicationDependency; +import org.apache.eagle.metadata.model.ApplicationDesc; +import org.apache.eagle.metadata.model.ApplicationEntity; +import org.apache.eagle.metadata.model.SiteEntity; +import org.apache.eagle.metadata.service.ApplicationEntityService; +import org.apache.eagle.metadata.service.SiteEntityService; +import org.apache.eagle.metadata.service.memory.ApplicationEntityServiceMemoryImpl; +import org.apache.eagle.metadata.service.memory.SiteEntityEntityServiceMemoryImpl; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; +import static org.mockito.Mockito.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; + +/** + * @Since 11/25/16. + */ +@RunWith(PowerMockRunner.class) +@PrepareForTest({ApplicationManagementServiceImpl.class}) +public class TestApplicationManagementServiceImpl { + + SiteEntityService siteEntityService; + ApplicationProviderService applicationProviderService; + ApplicationEntityService applicationEntityService; + Config config; + IMetadataDao alertMetadataService; + ApplicationHealthCheckService applicationHealthCheckService; + ApplicationManagementService applicationManagementService; + ApplicationOperations.InstallOperation installOperation; + ApplicationOperations.UninstallOperation uninstallOperation; + ApplicationOperations.StartOperation startOperation; + ApplicationOperations.StopOperation stopOperation; + ApplicationOperations.CheckStatusOperation checkStatusOperation; + ApplicationEntity resultEntity; + + @Before + public void setUp() throws EntityNotFoundException{ + siteEntityService = mock(SiteEntityEntityServiceMemoryImpl.class); + applicationEntityService = mock(ApplicationEntityServiceMemoryImpl.class); + config = ConfigFactory.parseMap(new HashMap() { + { + put("application.healthCheck.initialDelay", "10000"); + put("application.healthCheck.period", "10000"); + put("application.healthCheck.publisher.publisherImpl", "org.apache.eagle.app.service.impl.ApplicationHealthCheckEmailPublisher"); + put("application.healthCheck.publisher.dailySendHour", "11"); + put("service.timezone", "UTC"); + put("application.provider.loader", "org.apache.eagle.app.service.impl.ApplicationProviderSPILoader"); + put("dataSinkConfig.topic", "test_topic"); + put("dataSinkConfig.brokerList", "sandbox.hortonworks.com:6667"); + put("spoutNum", "4"); + put("appId", "testAppId"); + } + }); + alertMetadataService = new InMemMetadataDaoImpl(config); + applicationProviderService = new ApplicationProviderServiceImpl(config); + applicationHealthCheckService = mock(ApplicationHealthCheckServiceImpl.class); + applicationManagementService = new ApplicationManagementServiceImpl(config, siteEntityService, applicationProviderService, applicationEntityService, + alertMetadataService, applicationHealthCheckService); + installOperation = new ApplicationOperations.InstallOperation("sandbox", "TEST_APPLICATION", ApplicationEntity.Mode.LOCAL, "/user"); + startOperation = new ApplicationOperations.StartOperation(null, "TEST_APPLICATION_SANDBOX"); + stopOperation = new ApplicationOperations.StopOperation(null, "TEST_APPLICATION_SANDBOX"); + uninstallOperation = new ApplicationOperations.UninstallOperation(null, "TEST_APPLICATION_SANDBOX"); + checkStatusOperation = new ApplicationOperations.CheckStatusOperation(null, "TEST_APPLICATION_SANDBOX"); + when(siteEntityService.getBySiteId(anyString())).thenReturn(generateSiteEntity()); + } + + + @Test + public void testInstall() throws EntityNotFoundException { + when(applicationEntityService.create(any(ApplicationEntity.class))).thenReturn(generateCommonEntity()); + resultEntity = applicationManagementService.install(installOperation); + Assert.assertNotNull(resultEntity); + } + + @Test + public void testUnInstall() throws ApplicationWrongStatusException { + when(applicationEntityService.getByUUIDOrAppId(anyString(), anyString())).thenReturn(generateCommonEntity()); + resultEntity = applicationManagementService.uninstall(uninstallOperation); + verify(applicationEntityService, times(1)).delete(any(ApplicationEntity.class)); + } + + @Test + public void testStart() throws Exception { + when(applicationEntityService.getByUUIDOrAppId(anyString(), anyString())).thenReturn(generateCommonEntity()); + ApplicationAction applicationAction = mock(ApplicationAction.class); + PowerMockito.whenNew(ApplicationAction.class).withArguments(anyObject(), anyObject(), anyObject(), anyObject()).thenReturn(applicationAction); + resultEntity = applicationManagementService.start(startOperation); + verify(applicationAction, times(1)).doStart(); + verify(applicationEntityService, times(1)).create(any(ApplicationEntity.class)); + } + + @Test + public void testStop() throws Exception { + when(applicationEntityService.getByUUIDOrAppId(anyString(), anyString())).thenReturn(generateRunningEntity()); + ApplicationAction applicationAction = mock(ApplicationAction.class); + PowerMockito.whenNew(ApplicationAction.class).withArguments(anyObject(), anyObject(), anyObject(), anyObject()).thenReturn(applicationAction); + resultEntity = applicationManagementService.stop(stopOperation); + verify(applicationAction, times(1)).doStop(); + verify(applicationEntityService, times(1)).delete(any(ApplicationEntity.class)); + verify(applicationEntityService, times(1)).create(any(ApplicationEntity.class)); + } + + @Test + public void testGetStatus() throws Exception { + when(applicationEntityService.getByUUIDOrAppId(anyString(), anyString())).thenReturn(generateRunningEntity()); + ApplicationAction applicationAction = mock(ApplicationAction.class); + PowerMockito.whenNew(ApplicationAction.class).withArguments(anyObject(), anyObject(), anyObject(), anyObject()).thenReturn(applicationAction); + when(applicationAction.getStatus()).thenReturn(ApplicationEntity.Status.RUNNING); + ApplicationEntity.Status status = applicationManagementService.getStatus(checkStatusOperation); + Assert.assertEquals(ApplicationEntity.Status.RUNNING, status); + } + + private SiteEntity generateSiteEntity() { + SiteEntity siteEntity = new SiteEntity(); + siteEntity.setSiteId("sandbox"); + siteEntity.setSiteName("sandboxname"); + siteEntity.setDescription("sandboxdesc"); + return siteEntity; + } + + private ApplicationEntity generateCommonEntity() { + ApplicationDesc applicationDesc = new ApplicationDesc(); + ApplicationDependency applicationDependency = new ApplicationDependency(); + applicationDependency.setRequired(false); + applicationDesc.setType("TEST_APPLICATION"); + applicationDesc.setDependencies(new ArrayList(){{ + add(applicationDependency); + }}); + ApplicationEntity applicationEntity = new ApplicationEntity(); + applicationEntity.setSite(generateSiteEntity()); + applicationEntity.setDescriptor(applicationDesc); + applicationEntity.setMode(ApplicationEntity.Mode.LOCAL); + applicationEntity.setJarPath(applicationDesc.getJarPath()); + Map configure = new HashedMap(); + configure.put("a", "b"); + applicationEntity.setConfiguration(configure); + applicationEntity.setContext(configure); + applicationEntity.setAppId("testAppId"); + return applicationEntity; + } + + private ApplicationEntity generateRunningEntity() { + ApplicationEntity applicationEntity = generateCommonEntity(); + applicationEntity.setStatus(ApplicationEntity.Status.RUNNING); + return applicationEntity; + } +} http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/7976858e/eagle-core/eagle-common/src/test/java/org/apache/eagle/common/TestBase64.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-common/src/test/java/org/apache/eagle/common/TestBase64.java b/eagle-core/eagle-common/src/test/java/org/apache/eagle/common/TestBase64.java new file mode 100644 index 0000000..03ffeb7 --- /dev/null +++ b/eagle-core/eagle-common/src/test/java/org/apache/eagle/common/TestBase64.java @@ -0,0 +1,32 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.eagle.common; + +import junit.framework.Assert; +import org.junit.Test; + +/** + * @Since 11/22/16. + */ +public class TestBase64 { + + @Test + public void testBase64() { + String salted = "eagle"; + Assert.assertEquals(salted, Base64.decode(Base64.encode(salted))); + } +} http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/7976858e/eagle-core/eagle-common/src/test/java/org/apache/eagle/common/TestEagleExceptionWrapper.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-common/src/test/java/org/apache/eagle/common/TestEagleExceptionWrapper.java b/eagle-core/eagle-common/src/test/java/org/apache/eagle/common/TestEagleExceptionWrapper.java new file mode 100644 index 0000000..1730d9e --- /dev/null +++ b/eagle-core/eagle-common/src/test/java/org/apache/eagle/common/TestEagleExceptionWrapper.java @@ -0,0 +1,32 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.eagle.common; + +import junit.framework.Assert; +import org.junit.Test; + +/** + * @Since 11/22/16. + */ +public class TestEagleExceptionWrapper { + + @Test + public void testWrap() { + Exception exception = new Exception(); + Assert.assertTrue(EagleExceptionWrapper.wrap(exception).startsWith("java.lang.Exception")); + } +} http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/7976858e/eagle-core/eagle-common/src/test/java/org/apache/eagle/common/TestSerializableUtils.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-common/src/test/java/org/apache/eagle/common/TestSerializableUtils.java b/eagle-core/eagle-common/src/test/java/org/apache/eagle/common/TestSerializableUtils.java index 9767d9e..a0135e4 100644 --- a/eagle-core/eagle-common/src/test/java/org/apache/eagle/common/TestSerializableUtils.java +++ b/eagle-core/eagle-common/src/test/java/org/apache/eagle/common/TestSerializableUtils.java @@ -22,7 +22,6 @@ import org.junit.Test; import java.io.Serializable; -@Ignore public class TestSerializableUtils { @Test public void testSerializeObject() { http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/7976858e/eagle-core/eagle-common/src/test/java/org/apache/eagle/common/config/TestConfigParser.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-common/src/test/java/org/apache/eagle/common/config/TestConfigParser.java b/eagle-core/eagle-common/src/test/java/org/apache/eagle/common/config/TestConfigParser.java new file mode 100644 index 0000000..c5ef27f --- /dev/null +++ b/eagle-core/eagle-common/src/test/java/org/apache/eagle/common/config/TestConfigParser.java @@ -0,0 +1,36 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.eagle.common.config; + +import com.typesafe.config.Config; +import junit.framework.Assert; +import org.apache.commons.cli.ParseException; +import org.junit.Test; + +/** + * @Since 11/22/16. + */ +public class TestConfigParser { + + @Test + public void testLoadNullArgs() throws ParseException { + System.setProperty("config.resource", "application-test.conf"); + ConfigOptionParser configOptionParser = new ConfigOptionParser(); + Config config = configOptionParser.load(null); + Assert.assertEquals("UTC", config.getString("service.timezone")); + } +} http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/7976858e/eagle-core/eagle-metadata/eagle-metadata-base/pom.xml ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-metadata/eagle-metadata-base/pom.xml b/eagle-core/eagle-metadata/eagle-metadata-base/pom.xml index 8df0674..f58c34c 100644 --- a/eagle-core/eagle-metadata/eagle-metadata-base/pom.xml +++ b/eagle-core/eagle-metadata/eagle-metadata-base/pom.xml @@ -65,5 +65,9 @@ eagle-entity-base ${project.version} + + org.mockito + mockito-all + \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/7976858e/eagle-core/eagle-metadata/eagle-metadata-base/src/test/java/org/apache/eagle/metadata/model/TestConfiguration.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-metadata/eagle-metadata-base/src/test/java/org/apache/eagle/metadata/model/TestConfiguration.java b/eagle-core/eagle-metadata/eagle-metadata-base/src/test/java/org/apache/eagle/metadata/model/TestConfiguration.java new file mode 100644 index 0000000..daa9116 --- /dev/null +++ b/eagle-core/eagle-metadata/eagle-metadata-base/src/test/java/org/apache/eagle/metadata/model/TestConfiguration.java @@ -0,0 +1,67 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.eagle.metadata.model; +import org.junit.Assert; +import org.junit.Test; + +import javax.xml.bind.JAXBException; +import java.io.InputStream; + +/** + * @Since 11/23/16. + */ +public class TestConfiguration { + + @Test + public void testFromStream() throws JAXBException { + InputStream inputStream = this.getClass().getResourceAsStream("/application-test.xml"); + Configuration configuration = Configuration.fromStream(inputStream); + Assert.assertTrue(configuration.hasProperty("testkey1")); + } + + @Test + public void testFromResource() throws JAXBException { + String resource = "application-test.xml"; + Configuration configuration = Configuration.fromResource(resource); + Assert.assertEquals("testvalue1", configuration.getProperty("testkey1").getValue()); + Assert.assertEquals("testkey1", configuration.getProperty("testkey1").getName()); + } + + @Test + public void testFromString() throws JAXBException { + String xmlContext = "\n" + + " \n" + + " testkey1\n" + + " testvalue1\n" + + " testdesc1\n" + + " \n" + + " \n" + + " testkey2\n" + + " testvalue2\n" + + " testdesc2\n" + + " \n" + + " \n" + + " testkey3\n" + + " testvalue3\n" + + " testdesc3\n" + + " \n" + + ""; + Configuration configuration = Configuration.fromString(xmlContext); + Assert.assertEquals("testvalue1", configuration.getProperty("testkey1").getValue()); + Assert.assertEquals(3, configuration.size()); + } +} http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/7976858e/eagle-core/eagle-metadata/eagle-metadata-base/src/test/java/org/apache/eagle/metadata/persistence/MetadataStoreTest.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-metadata/eagle-metadata-base/src/test/java/org/apache/eagle/metadata/persistence/MetadataStoreTest.java b/eagle-core/eagle-metadata/eagle-metadata-base/src/test/java/org/apache/eagle/metadata/persistence/MetadataStoreTest.java new file mode 100644 index 0000000..6248249 --- /dev/null +++ b/eagle-core/eagle-metadata/eagle-metadata-base/src/test/java/org/apache/eagle/metadata/persistence/MetadataStoreTest.java @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.eagle.metadata.persistence; + +/** + * @Since 11/23/16. + */ +public class MetadataStoreTest extends MetadataStore { + + @Override + protected void configure() { + + } +} http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/7976858e/eagle-core/eagle-metadata/eagle-metadata-base/src/test/java/org/apache/eagle/metadata/persistence/TestMetadataStoreModuleFactory.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-metadata/eagle-metadata-base/src/test/java/org/apache/eagle/metadata/persistence/TestMetadataStoreModuleFactory.java b/eagle-core/eagle-metadata/eagle-metadata-base/src/test/java/org/apache/eagle/metadata/persistence/TestMetadataStoreModuleFactory.java new file mode 100644 index 0000000..0fd4e68 --- /dev/null +++ b/eagle-core/eagle-metadata/eagle-metadata-base/src/test/java/org/apache/eagle/metadata/persistence/TestMetadataStoreModuleFactory.java @@ -0,0 +1,33 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.eagle.metadata.persistence; + +import junit.framework.Assert; +import org.junit.Test; + +/** + * @Since 11/23/16. + */ +public class TestMetadataStoreModuleFactory { + + @Test + public void testGetModuleWithConf() { + System.setProperty("config.resource", "application-test.conf"); + MetadataStore instance = MetadataStoreModuleFactory.getModule(); + Assert.assertEquals("org.apache.eagle.metadata.persistence.MetadataStoreTest", instance.getName()); + } +} http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/7976858e/eagle-core/eagle-metadata/eagle-metadata-base/src/test/java/org/apache/eagle/metadata/service/TestApplicationEntityServiceMemoryImpl.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-metadata/eagle-metadata-base/src/test/java/org/apache/eagle/metadata/service/TestApplicationEntityServiceMemoryImpl.java b/eagle-core/eagle-metadata/eagle-metadata-base/src/test/java/org/apache/eagle/metadata/service/TestApplicationEntityServiceMemoryImpl.java new file mode 100644 index 0000000..b051681 --- /dev/null +++ b/eagle-core/eagle-metadata/eagle-metadata-base/src/test/java/org/apache/eagle/metadata/service/TestApplicationEntityServiceMemoryImpl.java @@ -0,0 +1,231 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.eagle.metadata.service; + +import junit.framework.Assert; +import org.apache.commons.collections.map.HashedMap; +import org.apache.eagle.metadata.exceptions.EntityNotFoundException; +import org.apache.eagle.metadata.model.ApplicationDesc; +import org.apache.eagle.metadata.model.ApplicationEntity; +import org.apache.eagle.metadata.model.SiteEntity; +import org.apache.eagle.metadata.service.memory.ApplicationEntityServiceMemoryImpl; +import org.junit.Test; +import org.mockito.Mockito; +import java.util.Collection; +import java.util.Map; + +/** + * @Since 11/23/16. + */ +public class TestApplicationEntityServiceMemoryImpl { + ApplicationDescService applicationDescService = Mockito.mock(ApplicationDescService.class); + ApplicationEntityService applicationEntityService = new ApplicationEntityServiceMemoryImpl(applicationDescService); + + @Test + public void testCreate() { + SiteEntity siteEntity = new SiteEntity(); + siteEntity.setSiteId("testsiteid"); + siteEntity.setSiteName("testsitename"); + siteEntity.setDescription("testdesc"); + ApplicationDesc applicationDesc = new ApplicationDesc(); + applicationDesc.setType("type1"); + ApplicationEntity applicationEntity = new ApplicationEntity(); + applicationEntity.setSite(siteEntity); + applicationEntity.setDescriptor(applicationDesc); + applicationEntity.setMode(ApplicationEntity.Mode.LOCAL); + applicationEntity.setJarPath(applicationDesc.getJarPath()); + Map configure = new HashedMap(); + configure.put("a", "b"); + applicationEntity.setConfiguration(configure); + applicationEntity.setContext(configure); + ApplicationEntity entity = applicationEntityService.create(applicationEntity); + System.out.println(entity.getUuid()); + Assert.assertNotNull(entity); + } + + @Test + public void testFindByUUID() throws EntityNotFoundException { + SiteEntity siteEntity = new SiteEntity(); + siteEntity.setSiteId("testsiteid"); + siteEntity.setSiteName("testsitename"); + siteEntity.setDescription("testdesc"); + ApplicationDesc applicationDesc = new ApplicationDesc(); + applicationDesc.setType("type1"); + ApplicationEntity applicationEntity = new ApplicationEntity(); + applicationEntity.setSite(siteEntity); + applicationEntity.setDescriptor(applicationDesc); + applicationEntity.setMode(ApplicationEntity.Mode.LOCAL); + applicationEntity.setJarPath(applicationDesc.getJarPath()); + Map configure = new HashedMap(); + configure.put("a", "b"); + applicationEntity.setConfiguration(configure); + applicationEntity.setContext(configure); + ApplicationEntity entity = applicationEntityService.create(applicationEntity); + String uuid = entity.getUuid(); + ApplicationEntity resultEntity = applicationEntityService.getByUUID(uuid); + Assert.assertNotNull(resultEntity); + } + + @Test + public void testFindBySiteId() throws EntityNotFoundException { + SiteEntity siteEntity = new SiteEntity(); + siteEntity.setSiteId("testsiteid"); + siteEntity.setSiteName("testsitename"); + siteEntity.setDescription("testdesc"); + ApplicationDesc applicationDesc = new ApplicationDesc(); + applicationDesc.setType("type1"); + ApplicationEntity applicationEntity = new ApplicationEntity(); + applicationEntity.setSite(siteEntity); + applicationEntity.setDescriptor(applicationDesc); + applicationEntity.setMode(ApplicationEntity.Mode.LOCAL); + applicationEntity.setJarPath(applicationDesc.getJarPath()); + Map configure = new HashedMap(); + configure.put("a", "b"); + applicationEntity.setConfiguration(configure); + applicationEntity.setContext(configure); + ApplicationEntity entity = applicationEntityService.create(applicationEntity); + Assert.assertNotNull(entity); + String siteId = entity.getSite().getSiteId(); + Collection resultEntities = applicationEntityService.findBySiteId(siteId); + Assert.assertEquals(1, resultEntities.size()); + } + + @Test + public void testGetBySiteIdAndAppType() { + SiteEntity siteEntity = new SiteEntity(); + siteEntity.setSiteId("testsiteid"); + siteEntity.setSiteName("testsitename"); + siteEntity.setDescription("testdesc"); + ApplicationDesc applicationDesc = new ApplicationDesc(); + applicationDesc.setType("type1"); + ApplicationEntity applicationEntity = new ApplicationEntity(); + applicationEntity.setSite(siteEntity); + applicationEntity.setDescriptor(applicationDesc); + applicationEntity.setMode(ApplicationEntity.Mode.LOCAL); + applicationEntity.setJarPath(applicationDesc.getJarPath()); + Map configure = new HashedMap(); + configure.put("a", "b"); + applicationEntity.setConfiguration(configure); + applicationEntity.setContext(configure); + ApplicationEntity entity = applicationEntityService.create(applicationEntity); + Assert.assertNotNull(entity); + String siteId = entity.getSite().getSiteId(); + String appType = entity.getDescriptor().getType(); + ApplicationEntity resultEntity = applicationEntityService.getBySiteIdAndAppType(siteId, appType); + Assert.assertNotNull(resultEntity); + } + + @Test(expected = IllegalArgumentException.class) + public void testGetByUUIDOrAppIdWhenBothNull() { + applicationEntityService.getByUUIDOrAppId(null, null); + } + + @Test + public void testGetByUUIDOrAppIdWhenNullAppId() { + SiteEntity siteEntity = new SiteEntity(); + siteEntity.setSiteId("testsiteid"); + siteEntity.setSiteName("testsitename"); + siteEntity.setDescription("testdesc"); + ApplicationDesc applicationDesc = new ApplicationDesc(); + applicationDesc.setType("type1"); + ApplicationEntity applicationEntity = new ApplicationEntity(); + applicationEntity.setSite(siteEntity); + applicationEntity.setDescriptor(applicationDesc); + applicationEntity.setMode(ApplicationEntity.Mode.LOCAL); + applicationEntity.setJarPath(applicationDesc.getJarPath()); + Map configure = new HashedMap(); + configure.put("a", "b"); + applicationEntity.setConfiguration(configure); + applicationEntity.setContext(configure); + ApplicationEntity entity = applicationEntityService.create(applicationEntity); + String uuid = entity.getUuid(); + ApplicationEntity resultEntity = applicationEntityService.getByUUIDOrAppId(uuid, null); + Assert.assertNotNull(resultEntity); + } + + @Test + public void testGetByUUIDOrAppIdNullUUID() { + SiteEntity siteEntity = new SiteEntity(); + siteEntity.setSiteId("testsiteid"); + siteEntity.setSiteName("testsitename"); + siteEntity.setDescription("testdesc"); + ApplicationDesc applicationDesc = new ApplicationDesc(); + applicationDesc.setType("type1"); + ApplicationEntity applicationEntity = new ApplicationEntity(); + applicationEntity.setSite(siteEntity); + applicationEntity.setDescriptor(applicationDesc); + applicationEntity.setMode(ApplicationEntity.Mode.LOCAL); + applicationEntity.setJarPath(applicationDesc.getJarPath()); + Map configure = new HashedMap(); + configure.put("a", "b"); + applicationEntity.setConfiguration(configure); + applicationEntity.setContext(configure); + ApplicationEntity entity = applicationEntityService.create(applicationEntity); + String appId = entity.getAppId(); + ApplicationEntity resultEntity = applicationEntityService.getByUUIDOrAppId(null, appId); + Assert.assertNotNull(resultEntity); + } + + @Test + public void testDelete() { + SiteEntity siteEntity = new SiteEntity(); + siteEntity.setSiteId("testsiteid"); + siteEntity.setSiteName("testsitename"); + siteEntity.setDescription("testdesc"); + ApplicationDesc applicationDesc = new ApplicationDesc(); + applicationDesc.setType("type1"); + ApplicationEntity applicationEntity = new ApplicationEntity(); + applicationEntity.setSite(siteEntity); + applicationEntity.setDescriptor(applicationDesc); + applicationEntity.setMode(ApplicationEntity.Mode.LOCAL); + applicationEntity.setJarPath(applicationDesc.getJarPath()); + Map configure = new HashedMap(); + configure.put("a", "b"); + applicationEntity.setConfiguration(configure); + applicationEntity.setContext(configure); + ApplicationEntity entity = applicationEntityService.create(applicationEntity); + ApplicationEntity resultEntity = applicationEntityService.delete(entity); + Assert.assertEquals(resultEntity, entity); + } + + @Test + public void testUpdate() { + SiteEntity siteEntity = new SiteEntity(); + siteEntity.setSiteId("testsiteid"); + siteEntity.setSiteName("testsitename"); + siteEntity.setDescription("testdesc"); + ApplicationDesc applicationDesc = new ApplicationDesc(); + applicationDesc.setType("type1"); + ApplicationEntity applicationEntity = new ApplicationEntity(); + applicationEntity.setSite(siteEntity); + applicationEntity.setDescriptor(applicationDesc); + applicationEntity.setMode(ApplicationEntity.Mode.LOCAL); + applicationEntity.setJarPath(applicationDesc.getJarPath()); + Map configure = new HashedMap(); + configure.put("a", "b"); + applicationEntity.setConfiguration(configure); + applicationEntity.setContext(configure); + ApplicationEntity entity = applicationEntityService.create(applicationEntity); + ApplicationEntity entity2 = entity; + configure.put("c", "d"); + entity2.setContext(configure); + ApplicationEntity resultEntity = applicationEntityService.update(entity2); + org.junit.Assert.assertEquals(2, resultEntity.getContext().size()); + Collection collection = applicationEntityService.findAll(); + Assert.assertEquals(1, collection.size()); + } +} http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/7976858e/eagle-core/eagle-metadata/eagle-metadata-base/src/test/java/org/apache/eagle/metadata/service/TestSiteEntityServiceMemoryImpl.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-metadata/eagle-metadata-base/src/test/java/org/apache/eagle/metadata/service/TestSiteEntityServiceMemoryImpl.java b/eagle-core/eagle-metadata/eagle-metadata-base/src/test/java/org/apache/eagle/metadata/service/TestSiteEntityServiceMemoryImpl.java new file mode 100644 index 0000000..645d18a --- /dev/null +++ b/eagle-core/eagle-metadata/eagle-metadata-base/src/test/java/org/apache/eagle/metadata/service/TestSiteEntityServiceMemoryImpl.java @@ -0,0 +1,97 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.eagle.metadata.service; + +import junit.framework.Assert; +import org.apache.eagle.metadata.exceptions.EntityNotFoundException; +import org.apache.eagle.metadata.model.SiteEntity; +import org.apache.eagle.metadata.service.memory.SiteEntityEntityServiceMemoryImpl; +import org.junit.Test; + +/** + * @Since 11/23/16. + */ +public class TestSiteEntityServiceMemoryImpl { + + SiteEntityService siteEntityService = new SiteEntityEntityServiceMemoryImpl(); + + @Test + public void testCreate() { + SiteEntity siteEntity = new SiteEntity(); + siteEntity.setSiteId("testsiteid"); + siteEntity.setSiteName("testsitename"); + siteEntity.setDescription("testdesc"); + SiteEntity resultEntity = siteEntityService.create(siteEntity); + Assert.assertNotNull(resultEntity); + } + + @Test + public void testGetBySiteIdAndUUID() throws EntityNotFoundException { + SiteEntity siteEntity = new SiteEntity(); + siteEntity.setSiteId("testsiteid"); + siteEntity.setSiteName("testsitename"); + siteEntity.setDescription("testdesc"); + SiteEntity entity = siteEntityService.create(siteEntity); + String uuid = entity.getUuid(); + SiteEntity resultEntity = siteEntityService.getByUUID(uuid); + Assert.assertNotNull(resultEntity); + String siteId = entity.getSiteId(); + resultEntity = siteEntityService.getBySiteId(siteId); + Assert.assertNotNull(resultEntity); + + } + + @Test(expected = EntityNotFoundException.class) + public void testGetBySiteIdFail() throws EntityNotFoundException { + siteEntityService.getBySiteId("fake uuid"); + } + + @Test + public void testDeleteBySiteId() throws EntityNotFoundException { + SiteEntity siteEntity = new SiteEntity(); + siteEntity.setSiteId("testsiteid"); + siteEntity.setSiteName("testsitename"); + siteEntity.setDescription("testdesc"); + SiteEntity entity = siteEntityService.create(siteEntity); + SiteEntity resultEntity = siteEntityService.deleteBySiteId(entity.getSiteId()); + Assert.assertEquals(resultEntity, entity); + } + + @Test + public void testDeleteBtUUID() throws EntityNotFoundException { + SiteEntity siteEntity = new SiteEntity(); + siteEntity.setSiteId("testsiteid"); + siteEntity.setSiteName("testsitename"); + siteEntity.setDescription("testdesc"); + SiteEntity entity = siteEntityService.create(siteEntity); + SiteEntity resultEntity = siteEntityService.deleteByUUID(entity.getUuid()); + Assert.assertEquals(resultEntity, entity); + } + + @Test + public void testUpdate() throws EntityNotFoundException { + SiteEntity siteEntity = new SiteEntity(); + siteEntity.setSiteId("testsiteid"); + siteEntity.setSiteName("testsitename"); + siteEntity.setDescription("testdesc"); + SiteEntity entity = siteEntityService.create(siteEntity); + SiteEntity entity2 = entity; + entity2.setSiteName("testsitename2"); + SiteEntity resultEntity = siteEntityService.update(entity2); + Assert.assertEquals("testsitename2", resultEntity.getSiteName()); + } +} http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/7976858e/eagle-core/eagle-metadata/eagle-metadata-base/src/test/resources/application-test.conf ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-metadata/eagle-metadata-base/src/test/resources/application-test.conf b/eagle-core/eagle-metadata/eagle-metadata-base/src/test/resources/application-test.conf new file mode 100644 index 0000000..e5209ed --- /dev/null +++ b/eagle-core/eagle-metadata/eagle-metadata-base/src/test/resources/application-test.conf @@ -0,0 +1,31 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with` +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +{ + metadata { + store = org.apache.eagle.metadata.persistence.MetadataStoreTest + jdbc { + username = null + password = null + driverClassName = "org.h2.Driver" + connection = "jdbc:h2:mem:test" + connectionProperties = "encoding=UTF8;timeout=60" + } + } + dataSinkConfig { + topic = "test_topic" + brokerList = "server.eagle.apache.org:6667" + } +} http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/7976858e/eagle-core/eagle-metadata/eagle-metadata-base/src/test/resources/application-test.xml ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-metadata/eagle-metadata-base/src/test/resources/application-test.xml b/eagle-core/eagle-metadata/eagle-metadata-base/src/test/resources/application-test.xml new file mode 100644 index 0000000..82e84ed --- /dev/null +++ b/eagle-core/eagle-metadata/eagle-metadata-base/src/test/resources/application-test.xml @@ -0,0 +1,17 @@ + + + testkey1 + testvalue1 + testdesc1 + + + testkey2 + testvalue2 + testdesc2 + + + testkey3 + testvalue3 + testdesc3 + + \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/7976858e/eagle-core/eagle-metadata/eagle-metadata-jdbc/src/test/java/org/apache/eagle/metadata/store/jdbc/ApplicationEntityServiceJDBCImplTest.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-metadata/eagle-metadata-jdbc/src/test/java/org/apache/eagle/metadata/store/jdbc/ApplicationEntityServiceJDBCImplTest.java b/eagle-core/eagle-metadata/eagle-metadata-jdbc/src/test/java/org/apache/eagle/metadata/store/jdbc/ApplicationEntityServiceJDBCImplTest.java index 0f3cd7d..ebca88c 100644 --- a/eagle-core/eagle-metadata/eagle-metadata-jdbc/src/test/java/org/apache/eagle/metadata/store/jdbc/ApplicationEntityServiceJDBCImplTest.java +++ b/eagle-core/eagle-metadata/eagle-metadata-jdbc/src/test/java/org/apache/eagle/metadata/store/jdbc/ApplicationEntityServiceJDBCImplTest.java @@ -18,6 +18,7 @@ package org.apache.eagle.metadata.store.jdbc; import org.apache.commons.collections.map.HashedMap; +import org.apache.eagle.alert.engine.coordinator.StreamDefinition; import org.apache.eagle.app.service.ApplicationProviderService; import org.apache.eagle.metadata.exceptions.EntityNotFoundException; import org.apache.eagle.metadata.model.ApplicationDesc; @@ -30,7 +31,9 @@ import org.junit.Test; import javax.inject.Inject; import java.sql.SQLException; +import java.util.ArrayList; import java.util.Collection; +import java.util.List; import java.util.Map; public class ApplicationEntityServiceJDBCImplTest extends JDBCMetadataTestBase { @@ -160,4 +163,67 @@ public class ApplicationEntityServiceJDBCImplTest extends JDBCMetadataTestBase { Assert.assertEquals(0, results.size()); } + @Test + public void testUpdateApplicationEntity() { + SiteEntity siteEntity = new SiteEntity(); + siteEntity.setSiteId("testsiteid"); + siteEntity.setSiteName("testsitename"); + siteEntity.setDescription("testdesc"); + siteEntityService.create(siteEntity); + ApplicationDesc applicationDesc = applicationProviderService.getApplicationDescByType("TEST_APP"); + ApplicationEntity applicationEntity = new ApplicationEntity(); + applicationEntity.setSite(siteEntity); + applicationEntity.setDescriptor(applicationDesc); + applicationEntity.setMode(ApplicationEntity.Mode.LOCAL); + applicationEntity.setJarPath(applicationDesc.getJarPath()); + Map configure = new HashedMap(); + configure.put("a", "b"); + applicationEntity.setConfiguration(configure); + applicationEntity.setContext(configure); + applicationEntityService.create(applicationEntity); + ApplicationEntity applicationEntity2 = applicationEntity; + configure.put("c", "d"); + applicationEntity2.setContext(configure); + Collection results = applicationEntityService.findAll(); + Assert.assertEquals(1, results.size()); + applicationEntity = applicationEntityService.update(applicationEntity2); + Assert.assertEquals(2, applicationEntity.getContext().size()); + results = applicationEntityService.findAll(); + Assert.assertEquals(1, results.size()); + } + + @Test + public void testGetByUUID() throws EntityNotFoundException { + SiteEntity siteEntity = new SiteEntity(); + siteEntity.setSiteId("testsiteid"); + siteEntity.setSiteName("testsitename"); + siteEntity.setDescription("testdesc"); + siteEntityService.create(siteEntity); + ApplicationDesc applicationDesc = applicationProviderService.getApplicationDescByType("TEST_APP"); + List streamDefinitions = new ArrayList<>(); + StreamDefinition sd = new StreamDefinition(); + sd.setStreamId("streamId"); + sd.setDescription("desc"); + sd.setValidate(true); + sd.setTimeseries(false); + sd.setDataSource("ds1"); + sd.setSiteId("siteId"); + streamDefinitions.add(sd); + applicationDesc.setStreams(streamDefinitions); + + ApplicationEntity applicationEntity = new ApplicationEntity(); + applicationEntity.setSite(siteEntity); + applicationEntity.setDescriptor(applicationDesc); + applicationEntity.setMode(ApplicationEntity.Mode.LOCAL); + applicationEntity.setJarPath(applicationDesc.getJarPath()); + Map configure = new HashedMap(); + configure.put("a", "b"); + applicationEntity.setConfiguration(configure); + applicationEntity.setContext(configure); + applicationEntityService.create(applicationEntity); + String appuuid = applicationEntity.getUuid(); + + ApplicationEntity applicationEntityFromDB = applicationEntityService.getByUUID(appuuid); + Assert.assertTrue(applicationEntityFromDB != null); + } } http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/7976858e/eagle-core/eagle-metadata/eagle-metadata-jdbc/src/test/resources/application.conf ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-metadata/eagle-metadata-jdbc/src/test/resources/application.conf b/eagle-core/eagle-metadata/eagle-metadata-jdbc/src/test/resources/application.conf index a834c34..f4a0038 100644 --- a/eagle-core/eagle-metadata/eagle-metadata-jdbc/src/test/resources/application.conf +++ b/eagle-core/eagle-metadata/eagle-metadata-jdbc/src/test/resources/application.conf @@ -24,4 +24,8 @@ connectionProperties = "encoding=UTF8;timeout=60" } } -} \ No newline at end of file + dataSinkConfig { + topic = "test_topic" + brokerList = "server.eagle.apache.org:6667" + } +}