From ba170b0a6bf2cc295a58ddbdc8da0cc2f6dbddfd Mon Sep 17 00:00:00 2001 From: Bartosz Gardziejewski Date: Thu, 30 Apr 2020 14:44:07 +0200 Subject: Fix failing integration test in netconf simulator Issue-ID: INT-1535 Signed-off-by: Bartosz Gardziejewski Change-Id: I75ec965ea580d96386c74834f146af4c7e44feca --- .../it/java/integration/NetconfFunctionsIT.java | 53 ++++++++++++++++------ .../onap/netconfsimulator/kafka/StoreService.java | 6 ++- 2 files changed, 44 insertions(+), 15 deletions(-) diff --git a/netconfsimulator/src/it/java/integration/NetconfFunctionsIT.java b/netconfsimulator/src/it/java/integration/NetconfFunctionsIT.java index 5d1a25a..495714b 100644 --- a/netconfsimulator/src/it/java/integration/NetconfFunctionsIT.java +++ b/netconfsimulator/src/it/java/integration/NetconfFunctionsIT.java @@ -53,6 +53,10 @@ import static org.assertj.core.api.Assertions.assertThat; @RunWith(BeforeAfterSpringTestRunner.class) public class NetconfFunctionsIT { + private static final String NEW_YANG_MODEL_NAME = "newyangmodel"; + private static final String NEW_YANG_MODEL_FILE = "newYangModel.yang"; + private static final String INITIAL_CONFIG_XML_FILE = "initialConfig.xml"; + private static final String CONFIG_NAME = "config2"; private static NetconfSimulatorClient client; private static ObjectMapper objectMapper; @@ -104,7 +108,7 @@ public class NetconfFunctionsIT { public void testShouldLoadModelEditConfigurationAndDeleteModule() throws IOException { // do load try (CloseableHttpResponse response = client - .loadModel("newyangmodel", "newYangModel.yang", "initialConfig.xml")) { + .loadModel(NEW_YANG_MODEL_NAME, NEW_YANG_MODEL_FILE, INITIAL_CONFIG_XML_FILE)) { assertResponseStatusCode(response, HttpStatus.OK); String original = client.getResponseContentAsString(response); assertThat(original).isEqualTo("\"Successfully started\"\n"); @@ -116,7 +120,7 @@ public class NetconfFunctionsIT { assertThat(afterUpdateConfigContent).isEqualTo("New configuration has been activated"); } // do delete - try (CloseableHttpResponse deleteResponse = client.deleteModel("newyangmodel")) { + try (CloseableHttpResponse deleteResponse = client.deleteModel(NEW_YANG_MODEL_NAME)) { assertResponseStatusCode(deleteResponse, HttpStatus.OK); String original = client.getResponseContentAsString(deleteResponse); assertThat(original).isEqualTo("\"Successfully deleted\"\n"); @@ -179,7 +183,7 @@ public class NetconfFunctionsIT { @Test public void testShouldLoadNewYangModelAndReconfigure() throws IOException { try (CloseableHttpResponse response = client - .loadModel("newyangmodel", "newYangModel.yang", "initialConfig.xml")) { + .loadModel(NEW_YANG_MODEL_NAME, NEW_YANG_MODEL_FILE, INITIAL_CONFIG_XML_FILE)) { assertResponseStatusCode(response, HttpStatus.OK); String original = client.getResponseContentAsString(response); @@ -188,23 +192,44 @@ public class NetconfFunctionsIT { } } - // ToDo: fix this integration test - // https://jira.onap.org/browse/INT-1535 - public void shouldGetLoadedModelByName() throws IOException { + @Test + public void shouldGetLoadedModelByName() throws IOException, InterruptedException { testShouldLoadNewYangModelAndReconfigure(); - try (CloseableHttpResponse response = client.getConfigByModelAndContainerNames("newyangmodel", "config2")) { - assertResponseStatusCode(response, HttpStatus.OK); - String config = client.getResponseContentAsString(response); - - assertThat(config).isEqualTo( - "\n" - + " 100\n" - + "\n"); + if(checkIfModelIsPresentWithRetry(NEW_YANG_MODEL_NAME, CONFIG_NAME,4,500)) { + try (CloseableHttpResponse response = client.getConfigByModelAndContainerNames(NEW_YANG_MODEL_NAME, CONFIG_NAME)) { + assertResponseStatusCode(response, HttpStatus.OK); + String config = client.getResponseContentAsString(response); + + assertThat(config).isEqualTo( + "\n" + + " 100\n" + + "\n"); + } + } else { + fail("Could not find new YANG model by name"); } } + private boolean checkIfModelIsPresentWithRetry(String model, String container,int retryCount,int interval) throws IOException, InterruptedException { + boolean isModelPresent = false; + + for(int i=0 ; i consumerFactory; static final List TOPICS_TO_SUBSCRIBE = Collections.singletonList(CONFIG_TOPIC); @@ -69,6 +70,9 @@ public class StoreService { ConsumerRecords consumerRecords = pollConsumerRecords(consumer); consumerRecords.forEach(consumerRecord -> messages.add(new Message(consumerRecord.timestamp(), consumerRecord.value()))); + } catch (NoSuchElementException e) { + log.warn("not able to create consumer and to poll messages"); + return Collections.emptyList(); } return messages; } -- cgit 1.2.3-korg