diff options
author | mark.j.leonard <mark.j.leonard@gmail.com> | 2019-02-15 11:16:58 +0000 |
---|---|---|
committer | mark.j.leonard <mark.j.leonard@gmail.com> | 2019-02-15 11:16:58 +0000 |
commit | 209cd56d7f2f885a94fc5f937c4376fc0ffbd922 (patch) | |
tree | 2c4d56bded12a9134bd43b42eef524993330558b /src/test/java/org/onap | |
parent | 13b3d5d42bae10ce2733c86814177c3e31eb2014 (diff) |
Convert tests with Mocking to SpringBootTest
Remove the dependency on Mockito and instead use the Spring framework
for testing with Mocks. This allows greater control over the properties
that are used by the test classes.
Change-Id: I3a72d41f3015f831f425f99cf44417bccdb2c823
Issue-ID: AAI-2057
Signed-off-by: mark.j.leonard <mark.j.leonard@gmail.com>
Diffstat (limited to 'src/test/java/org/onap')
4 files changed, 67 insertions, 40 deletions
diff --git a/src/test/java/org/onap/aai/validation/TestApplication.java b/src/test/java/org/onap/aai/validation/TestApplication.java index 26d480a..3dfa177 100644 --- a/src/test/java/org/onap/aai/validation/TestApplication.java +++ b/src/test/java/org/onap/aai/validation/TestApplication.java @@ -1,7 +1,10 @@ /** - * ============LICENSE_START=================================================== + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright (c) 2018-2019 AT&T Intellectual Property. All rights reserved. * Copyright (c) 2018-2019 European Software Marketing Ltd. - * ============================================================================ + * ================================================================================ * Licensed 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 @@ -13,7 +16,7 @@ * 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. - * ============LICENSE_END===================================================== + * ============LICENSE_END========================================================= */ package org.onap.aai.validation; @@ -21,11 +24,17 @@ import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.TestPropertySource; /** * Invoke the Spring Boot Application (primarily for code coverage). * */ +@SpringBootTest(classes = ValidationServiceApplication.class) +@TestPropertySource(locations = {"classpath:oxm-reader/schemaIngest.properties", "classpath:application.properties"}) +@ContextConfiguration(locations = {"classpath:validation-service-beans.xml"}) public class TestApplication { @Rule @@ -35,6 +44,7 @@ public class TestApplication { public void init() { System.setProperty("CONFIG_HOME", "src/test/resources/model-validation/instance-validator"); System.setProperty("APP_HOME", "."); + System.setProperty("schema.translator.list", "config"); System.clearProperty("KEY_STORE_PASSWORD"); } @@ -46,4 +56,11 @@ public class TestApplication { ValidationServiceApplication.main(null); } + @Test + public void testApplicationWithNullKeyStorePassword() { + expectedEx.expect(IllegalArgumentException.class); + expectedEx.expectMessage("roperty KEY_STORE_PASSWORD not set"); + ValidationServiceApplication.main(new String[] {}); + } + } diff --git a/src/test/java/org/onap/aai/validation/config/TestTopicConfig.java b/src/test/java/org/onap/aai/validation/config/TestTopicConfig.java index 30e28d8..f323331 100644 --- a/src/test/java/org/onap/aai/validation/config/TestTopicConfig.java +++ b/src/test/java/org/onap/aai/validation/config/TestTopicConfig.java @@ -1,20 +1,24 @@ -/* - * ============LICENSE_START=================================================== - * Copyright (c) 2018 Amdocs - * ============================================================================ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright (c) 2018-2019 AT&T Intellectual Property. All rights reserved. + * Copyright (c) 2018-2019 European Software Marketing Ltd. + * ================================================================================ * Licensed 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 + * 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. - * ============LICENSE_END===================================================== + * ============LICENSE_END========================================================= */ + package org.onap.aai.validation.config; import static org.hamcrest.Matchers.containsInAnyOrder; @@ -23,17 +27,21 @@ import static org.junit.Assert.assertThat; import java.util.List; import java.util.Properties; -import javax.annotation.Resource; import javax.inject.Inject; import org.junit.Test; import org.junit.runner.RunWith; import org.onap.aai.validation.config.TopicConfig.Topic; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.Import; import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - +@SpringBootTest @RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(locations = {"classpath:/topic-config/test-validation-service-beans.xml"}) +@Import(TopicPropertiesConfig.class) +@TestPropertySource(locations = { "classpath:test-application.properties" }) +@ContextConfiguration(locations = { "classpath:topic-config/test-validation-service-beans.xml" }) public class TestTopicConfig { static { @@ -41,26 +49,22 @@ public class TestTopicConfig { } @Inject - private TopicConfig topicConfigurations; + private TopicConfig topicConfig; - @Resource(name = "topicProperties") + @Inject private Properties topicProperties; - @Test public void testGetTopicProperties() throws Exception { assertThat(topicProperties.getProperty("aai-event.name"), is("aai-event")); assertThat(topicProperties.getProperty("aai-data-export.name"), is("aai-data-export")); } - - @Test public void testGetConsumerTopicsFromTopicConfig() throws Exception { - assertThat(topicConfigurations.getConsumerTopicNames(), containsInAnyOrder("aai-event", "aai-data-export")); + assertThat(topicConfig.getConsumerTopicNames(), containsInAnyOrder("aai-event", "aai-data-export")); } - @Test public void testGetConsumerTopicConfigurationObjects() throws Exception { Topic eventTopic = new TopicConfig("aai-event", "aai-data-integrity").new Topic(); @@ -81,7 +85,7 @@ public class TestTopicConfig { exportTopic.setConsumerId("export-dummy-consumer-id"); exportTopic.setTransportType("export-dummy-transport-type"); - List<Topic> consumerTopics = topicConfigurations.getConsumerTopics(); + List<Topic> consumerTopics = topicConfig.getConsumerTopics(); assertThat(consumerTopics, containsInAnyOrder(eventTopic, exportTopic)); } @@ -96,10 +100,8 @@ public class TestTopicConfig { integrityTopic.setPassword("integrity-dummy-password"); integrityTopic.setTransportType("integrity-dummy-transport-type"); - List<Topic> publisherTopics = topicConfigurations.getPublisherTopics(); + List<Topic> publisherTopics = topicConfig.getPublisherTopics(); assertThat(publisherTopics, containsInAnyOrder(integrityTopic)); } - - } diff --git a/src/test/java/org/onap/aai/validation/modeldriven/validator/TestModelDrivenValidator.java b/src/test/java/org/onap/aai/validation/modeldriven/validator/TestModelDrivenValidator.java index de06357..5a58f41 100644 --- a/src/test/java/org/onap/aai/validation/modeldriven/validator/TestModelDrivenValidator.java +++ b/src/test/java/org/onap/aai/validation/modeldriven/validator/TestModelDrivenValidator.java @@ -1,7 +1,10 @@ /** - * ============LICENSE_START=================================================== - * Copyright (c) 2018-2019 Amdocs - * ============================================================================ + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright (c) 2018-2019 AT&T Intellectual Property. All rights reserved. + * Copyright (c) 2018-2019 European Software Marketing Ltd. + * ================================================================================ * Licensed 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 @@ -13,7 +16,7 @@ * 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. - * ============LICENSE_END===================================================== + * ============LICENSE_END========================================================= */ package org.onap.aai.validation.modeldriven.validator; @@ -35,8 +38,6 @@ import org.dom4j.Element; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; import org.onap.aai.validation.controller.ValidationController; @@ -46,10 +47,13 @@ import org.onap.aai.validation.modeldriven.parser.XMLModelParser; import org.onap.aai.validation.result.ValidationResult; import org.onap.aai.validation.result.Violation; import org.onap.aai.validation.test.util.TestUtil; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +@SpringBootTest @RunWith(SpringJUnit4ClassRunner.class) @TestPropertySource(locations = {"classpath:oxm-reader/schemaIngest.properties"}) @ContextConfiguration(locations = {"classpath:model-validation/instance-validator/test-validation-service-beans.xml"}) @@ -63,10 +67,9 @@ public class TestModelDrivenValidator { private static final String MODEL_ID_ATTRIBUTE_MNV = "model-name-version-id"; private static final String MODEL_ID_ATTRIBUTE_MID = "model-id"; - @Mock + @MockBean private ModelCacheManager mockModelCacheManager; - @InjectMocks @Inject private ModelDrivenValidator modelDrivenValidator; diff --git a/src/test/java/org/onap/aai/validation/services/TestInfoService.java b/src/test/java/org/onap/aai/validation/services/TestInfoService.java index ac9591a..f99748a 100644 --- a/src/test/java/org/onap/aai/validation/services/TestInfoService.java +++ b/src/test/java/org/onap/aai/validation/services/TestInfoService.java @@ -1,7 +1,10 @@ /** - * ============LICENSE_START=================================================== - * Copyright (c) 2018-2019 Amdocs - * ============================================================================ + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright (c) 2018-2019 AT&T Intellectual Property. All rights reserved. + * Copyright (c) 2018-2019 European Software Marketing Ltd. + * ================================================================================ * Licensed 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 @@ -13,7 +16,7 @@ * 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. - * ============LICENSE_END===================================================== + * ============LICENSE_END========================================================= */ package org.onap.aai.validation.services; @@ -37,13 +40,15 @@ import org.onap.aai.validation.exception.ValidationServiceException; import org.onap.aai.validation.publisher.MockEventPublisher; import org.onap.aai.validation.test.util.TestEntity; import org.onap.aai.validation.test.util.TestUtil; +import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +@SpringBootTest @RunWith(SpringJUnit4ClassRunner.class) -@TestPropertySource(locations = {"classpath:oxm-reader/schemaIngest.properties", "classpath:application.properties"}) -@ContextConfiguration(locations = {"classpath:/info-service/test-validation-service-beans.xml"}) +@TestPropertySource(locations = { "classpath:oxm-reader/schemaIngest.properties", "classpath:application.properties" }) +@ContextConfiguration(locations = { "classpath:/info-service/test-validation-service-beans.xml" }) public class TestInfoService { static { @@ -51,9 +56,9 @@ public class TestInfoService { } enum TestData { - // @formatter:off - VSERVER("rule-driven-validator/test_events/vserver-create-event.json"); - // @formatter:on + VSERVER( + "rule-driven-validator/test_events/vserver-create-event.json" + ); private String filename; |