aboutsummaryrefslogtreecommitdiffstats
path: root/test/mocks/pnfsimulator/pnfsimulator/src/test/java/org/onap/pnfsimulator/simulator
diff options
context:
space:
mode:
Diffstat (limited to 'test/mocks/pnfsimulator/pnfsimulator/src/test/java/org/onap/pnfsimulator/simulator')
-rw-r--r--test/mocks/pnfsimulator/pnfsimulator/src/test/java/org/onap/pnfsimulator/simulator/IncrementProviderImplTest.java78
-rw-r--r--test/mocks/pnfsimulator/pnfsimulator/src/test/java/org/onap/pnfsimulator/simulator/KeywordsExtractorInvalidRandomIntegerTest.java67
-rw-r--r--test/mocks/pnfsimulator/pnfsimulator/src/test/java/org/onap/pnfsimulator/simulator/KeywordsExtractorInvalidRandomStringTest.java67
-rw-r--r--test/mocks/pnfsimulator/pnfsimulator/src/test/java/org/onap/pnfsimulator/simulator/KeywordsExtractorInvalidTimestampTest.java65
-rw-r--r--test/mocks/pnfsimulator/pnfsimulator/src/test/java/org/onap/pnfsimulator/simulator/KeywordsExtractorValidRandomIntegerTest.java66
-rw-r--r--test/mocks/pnfsimulator/pnfsimulator/src/test/java/org/onap/pnfsimulator/simulator/KeywordsExtractorValidRandomPrimitiveIntegerTest.java66
-rw-r--r--test/mocks/pnfsimulator/pnfsimulator/src/test/java/org/onap/pnfsimulator/simulator/KeywordsExtractorValidRandomStringTest.java69
-rw-r--r--test/mocks/pnfsimulator/pnfsimulator/src/test/java/org/onap/pnfsimulator/simulator/KeywordsExtractorValidTimestampPrimitiveTest.java66
-rw-r--r--test/mocks/pnfsimulator/pnfsimulator/src/test/java/org/onap/pnfsimulator/simulator/KeywordsExtractorValidTimestampTest.java67
-rw-r--r--test/mocks/pnfsimulator/pnfsimulator/src/test/java/org/onap/pnfsimulator/simulator/KeywordsHandlerTest.java304
-rw-r--r--test/mocks/pnfsimulator/pnfsimulator/src/test/java/org/onap/pnfsimulator/simulator/KeywordsValueProviderTest.java81
-rw-r--r--test/mocks/pnfsimulator/pnfsimulator/src/test/java/org/onap/pnfsimulator/simulator/SimulatorServiceTest.java226
-rw-r--r--test/mocks/pnfsimulator/pnfsimulator/src/test/java/org/onap/pnfsimulator/simulator/TemplatePatcherTest.java164
-rw-r--r--test/mocks/pnfsimulator/pnfsimulator/src/test/java/org/onap/pnfsimulator/simulator/TemplateReaderTest.java51
-rw-r--r--test/mocks/pnfsimulator/pnfsimulator/src/test/java/org/onap/pnfsimulator/simulator/client/HttpClientAdapterImplTest.java97
-rw-r--r--test/mocks/pnfsimulator/pnfsimulator/src/test/java/org/onap/pnfsimulator/simulator/client/utils/ssl/SslSupportLevelTest.java52
-rw-r--r--test/mocks/pnfsimulator/pnfsimulator/src/test/java/org/onap/pnfsimulator/simulator/scheduler/EventJobTest.java90
-rw-r--r--test/mocks/pnfsimulator/pnfsimulator/src/test/java/org/onap/pnfsimulator/simulator/scheduler/EventSchedulerTest.java143
18 files changed, 0 insertions, 1819 deletions
diff --git a/test/mocks/pnfsimulator/pnfsimulator/src/test/java/org/onap/pnfsimulator/simulator/IncrementProviderImplTest.java b/test/mocks/pnfsimulator/pnfsimulator/src/test/java/org/onap/pnfsimulator/simulator/IncrementProviderImplTest.java
deleted file mode 100644
index 53f02da0e..000000000
--- a/test/mocks/pnfsimulator/pnfsimulator/src/test/java/org/onap/pnfsimulator/simulator/IncrementProviderImplTest.java
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * PNF-REGISTRATION-HANDLER
- * ================================================================================
- * Copyright (C) 2018 Nokia. All rights reserved.
- * ================================================================================
- * 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
- *
- * 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=========================================================
- */
-
-package org.onap.pnfsimulator.simulator;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.jupiter.api.Assertions.assertThrows;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-import java.util.Optional;
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
-import org.mockito.ArgumentCaptor;
-import org.mockito.Mock;
-import org.onap.pnfsimulator.event.EventData;
-import org.onap.pnfsimulator.event.EventDataRepository;
-
-public class IncrementProviderImplTest {
- private IncrementProvider incrementProvider;
-
- @Mock
- private EventDataRepository eventDataRepositoryMock;
-
- @BeforeEach
- void setUp() {
- eventDataRepositoryMock = mock(EventDataRepository.class);
- incrementProvider = new IncrementProviderImpl(eventDataRepositoryMock);
- }
-
- @Test
- public void getAndIncrementTest() {
- ArgumentCaptor<EventData> eventDataArgumentCaptor = ArgumentCaptor.forClass(EventData.class);
- String eventId = "1";
- int initialIncrementValue = 0;
- int expectedValue = initialIncrementValue + 1;
- EventData eventData = EventData.builder().id(eventId).incrementValue(initialIncrementValue).build();
- Optional<EventData> optional = Optional.of(eventData);
-
- when(eventDataRepositoryMock.findById(eventId)).thenReturn(optional);
-
- int value = incrementProvider.getAndIncrement(eventId);
-
- verify(eventDataRepositoryMock).save(eventDataArgumentCaptor.capture());
-
- assertThat(value).isEqualTo(expectedValue);
- assertThat(eventDataArgumentCaptor.getValue().getIncrementValue()).isEqualTo(expectedValue);
-
- }
-
- @Test
- public void shouldThrowOnNonExistingEvent() {
- Optional<EventData> emptyOptional = Optional.empty();
- String nonExistingEventId = "THIS_DOES_NOT_EXIST";
- when(eventDataRepositoryMock.findById(nonExistingEventId)).thenReturn(emptyOptional);
-
- assertThrows(EventNotFoundException.class,
- () -> incrementProvider.getAndIncrement(nonExistingEventId));
- }
-}
diff --git a/test/mocks/pnfsimulator/pnfsimulator/src/test/java/org/onap/pnfsimulator/simulator/KeywordsExtractorInvalidRandomIntegerTest.java b/test/mocks/pnfsimulator/pnfsimulator/src/test/java/org/onap/pnfsimulator/simulator/KeywordsExtractorInvalidRandomIntegerTest.java
deleted file mode 100644
index 8198e95a9..000000000
--- a/test/mocks/pnfsimulator/pnfsimulator/src/test/java/org/onap/pnfsimulator/simulator/KeywordsExtractorInvalidRandomIntegerTest.java
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * PNF-REGISTRATION-HANDLER
- * ================================================================================
- * Copyright (C) 2018 Nokia. All rights reserved.
- * ================================================================================
- * 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
- *
- * 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=========================================================
- */
-
-package org.onap.pnfsimulator.simulator;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-
-import java.util.Arrays;
-import java.util.Collection;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
-
-@RunWith(Parameterized.class)
-public class KeywordsExtractorInvalidRandomIntegerTest {
-
- private final String keyword;
- private KeywordsExtractor keywordsExtractor;
-
- private static final Collection INVALID_INTEGER_KEYWORDS = Arrays.asList(new Object[][]{
- {"#RandoInteger"},
- {"#Randominteger(23,11)"},
- {"#randomInteger(11,34)"},
- {"#Random_Integer(11,13)"},
- {"#RandomInteger(11)"},
- {"RandomInteger(11)"},
- {"RandomInteger"}
- });
-
- public KeywordsExtractorInvalidRandomIntegerTest(String keyword) {
- this.keyword = keyword;
- }
-
- @Before
- public void setUp() {
- this.keywordsExtractor = new KeywordsExtractor();
- }
-
- @Parameterized.Parameters
- public static Collection data() {
- return INVALID_INTEGER_KEYWORDS;
- }
-
- @Test
- public void checkValidRandomStringKeyword() {
- assertEquals(keywordsExtractor.substituteStringKeyword(this.keyword, 1), this.keyword);
- }
-
-}
diff --git a/test/mocks/pnfsimulator/pnfsimulator/src/test/java/org/onap/pnfsimulator/simulator/KeywordsExtractorInvalidRandomStringTest.java b/test/mocks/pnfsimulator/pnfsimulator/src/test/java/org/onap/pnfsimulator/simulator/KeywordsExtractorInvalidRandomStringTest.java
deleted file mode 100644
index 6834c0dc6..000000000
--- a/test/mocks/pnfsimulator/pnfsimulator/src/test/java/org/onap/pnfsimulator/simulator/KeywordsExtractorInvalidRandomStringTest.java
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * PNF-REGISTRATION-HANDLER
- * ================================================================================
- * Copyright (C) 2018 Nokia. All rights reserved.
- * ================================================================================
- * 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
- *
- * 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=========================================================
- */
-
-package org.onap.pnfsimulator.simulator;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-
-import java.util.Arrays;
-import java.util.Collection;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
-
-@RunWith(Parameterized.class)
-public class KeywordsExtractorInvalidRandomStringTest {
-
- private final String keyword;
- private KeywordsExtractor keywordsExtractor;
-
- private static final Collection INVALID_STRING_KEYWORDS = Arrays.asList(new Object[][]{
- {"#RandoString"},
- {"#Randomstring(23)"},
- {"#randomString(11)"},
- {"#Random_String(11)"},
- {"#RandomString(11,10)"},
- {"RandomString(11)"},
- {"RandomString"}
- });
-
- public KeywordsExtractorInvalidRandomStringTest(String keyword) {
- this.keyword = keyword;
- }
-
- @Before
- public void setUp() {
- this.keywordsExtractor = new KeywordsExtractor();
- }
-
- @Parameterized.Parameters
- public static Collection data() {
- return INVALID_STRING_KEYWORDS;
- }
-
- @Test
- public void checkValidRandomStringKeyword() {
- assertEquals(keywordsExtractor.substituteStringKeyword(this.keyword, 1).length(), this.keyword.length());
- }
-
-}
diff --git a/test/mocks/pnfsimulator/pnfsimulator/src/test/java/org/onap/pnfsimulator/simulator/KeywordsExtractorInvalidTimestampTest.java b/test/mocks/pnfsimulator/pnfsimulator/src/test/java/org/onap/pnfsimulator/simulator/KeywordsExtractorInvalidTimestampTest.java
deleted file mode 100644
index eda40707b..000000000
--- a/test/mocks/pnfsimulator/pnfsimulator/src/test/java/org/onap/pnfsimulator/simulator/KeywordsExtractorInvalidTimestampTest.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * PNF-REGISTRATION-HANDLER
- * ================================================================================
- * Copyright (C) 2018 Nokia. All rights reserved.
- * ================================================================================
- * 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
- *
- * 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=========================================================
- */
-
-package org.onap.pnfsimulator.simulator;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-
-import java.util.Arrays;
-import java.util.Collection;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
-
-@RunWith(Parameterized.class)
-public class KeywordsExtractorInvalidTimestampTest {
-
- private final String keyword;
- private KeywordsExtractor keywordsExtractor;
-
- private static final Collection INVALID_TIMESTAMP_KEYWORDS = Arrays.asList(new Object[][]{
- {"#Timesamp"},
- {"#Timestamp(10)"},
- {"#timestamp"},
- {"#Timestamp(11,13)"},
- {"Timestamp"}
- });
-
- public KeywordsExtractorInvalidTimestampTest(String keyword) {
- this.keyword = keyword;
- }
-
- @Before
- public void setUp() {
- this.keywordsExtractor = new KeywordsExtractor();
- }
-
- @Parameterized.Parameters
- public static Collection data() {
- return INVALID_TIMESTAMP_KEYWORDS;
- }
-
- @Test
- public void checkValidRandomStringKeyword() {
- assertEquals(keywordsExtractor.substituteStringKeyword(this.keyword, 1), this.keyword);
- }
-
-}
diff --git a/test/mocks/pnfsimulator/pnfsimulator/src/test/java/org/onap/pnfsimulator/simulator/KeywordsExtractorValidRandomIntegerTest.java b/test/mocks/pnfsimulator/pnfsimulator/src/test/java/org/onap/pnfsimulator/simulator/KeywordsExtractorValidRandomIntegerTest.java
deleted file mode 100644
index be79488b5..000000000
--- a/test/mocks/pnfsimulator/pnfsimulator/src/test/java/org/onap/pnfsimulator/simulator/KeywordsExtractorValidRandomIntegerTest.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * PNF-REGISTRATION-HANDLER
- * ================================================================================
- * Copyright (C) 2018 Nokia. All rights reserved.
- * ================================================================================
- * 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
- *
- * 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=========================================================
- */
-
-package org.onap.pnfsimulator.simulator;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-
-import java.util.Arrays;
-import java.util.Collection;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
-
-@RunWith(Parameterized.class)
-public class KeywordsExtractorValidRandomIntegerTest {
-
- private final String keyword;
- private final String shouldParseTo;
- private KeywordsExtractor keywordsExtractor;
-
- private static final Collection VALID_INTEGER_KEYWORDS = Arrays.asList(new Object[][]{
- {"#RandomInteger(23,23)", "23"},
- {"#RandomInteger(6, 6)12", "612"},
- {"1#RandomInteger(11,11)", "111"},
- {"1#RandomInteger(11,11)2", "1112"}
- });
-
- public KeywordsExtractorValidRandomIntegerTest(String keyword, String shouldParseTo) {
- this.keyword = keyword;
- this.shouldParseTo = shouldParseTo;
- }
-
- @Before
- public void setUp() {
- this.keywordsExtractor = new KeywordsExtractor();
- }
-
- @Parameterized.Parameters
- public static Collection data() {
- return VALID_INTEGER_KEYWORDS;
- }
-
- @Test
- public void checkValidRandomStringKeyword() {
- assertEquals(keywordsExtractor.substituteStringKeyword(this.keyword, 1), this.shouldParseTo);
- }
-
-}
diff --git a/test/mocks/pnfsimulator/pnfsimulator/src/test/java/org/onap/pnfsimulator/simulator/KeywordsExtractorValidRandomPrimitiveIntegerTest.java b/test/mocks/pnfsimulator/pnfsimulator/src/test/java/org/onap/pnfsimulator/simulator/KeywordsExtractorValidRandomPrimitiveIntegerTest.java
deleted file mode 100644
index fd72a5145..000000000
--- a/test/mocks/pnfsimulator/pnfsimulator/src/test/java/org/onap/pnfsimulator/simulator/KeywordsExtractorValidRandomPrimitiveIntegerTest.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * PNF-REGISTRATION-HANDLER
- * ================================================================================
- * Copyright (C) 2018 Nokia. All rights reserved.
- * ================================================================================
- * 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
- *
- * 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=========================================================
- */
-
-package org.onap.pnfsimulator.simulator;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-
-import java.util.Arrays;
-import java.util.Collection;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
-
-@RunWith(Parameterized.class)
-public class KeywordsExtractorValidRandomPrimitiveIntegerTest {
-
- private final String keyword;
- private final Integer shouldParseTo;
- private KeywordsExtractor keywordsExtractor;
-
- private static final Collection VALID_INTEGER_KEYWORDS = Arrays.asList(new Object[][]{
- {"#RandomPrimitiveInteger(23,23)", 23},
- {"#RandomPrimitiveInteger(6, 6)12", 6},
- {"1#RandomPrimitiveInteger(11,11)", 11},
- {"1#RandomPrimitiveInteger(11,11)2", 11}
- });
-
- public KeywordsExtractorValidRandomPrimitiveIntegerTest(String keyword, Integer shouldParseTo) {
- this.keyword = keyword;
- this.shouldParseTo = shouldParseTo;
- }
-
- @Before
- public void setUp() {
- this.keywordsExtractor = new KeywordsExtractor();
- }
-
- @Parameterized.Parameters
- public static Collection data() {
- return VALID_INTEGER_KEYWORDS;
- }
-
- @Test
- public void checkValidRandomStringKeyword() {
- assertEquals(keywordsExtractor.substitutePrimitiveKeyword(this.keyword), this.shouldParseTo);
- }
-
-}
diff --git a/test/mocks/pnfsimulator/pnfsimulator/src/test/java/org/onap/pnfsimulator/simulator/KeywordsExtractorValidRandomStringTest.java b/test/mocks/pnfsimulator/pnfsimulator/src/test/java/org/onap/pnfsimulator/simulator/KeywordsExtractorValidRandomStringTest.java
deleted file mode 100644
index f0fdc0ff3..000000000
--- a/test/mocks/pnfsimulator/pnfsimulator/src/test/java/org/onap/pnfsimulator/simulator/KeywordsExtractorValidRandomStringTest.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * PNF-REGISTRATION-HANDLER
- * ================================================================================
- * Copyright (C) 2018 Nokia. All rights reserved.
- * ================================================================================
- * 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
- *
- * 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=========================================================
- */
-
-package org.onap.pnfsimulator.simulator;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.onap.pnfsimulator.simulator.KeywordsValueProvider.DEFAULT_STRING_LENGTH;
-
-import java.util.Arrays;
-import java.util.Collection;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
-
-@RunWith(Parameterized.class)
-public class KeywordsExtractorValidRandomStringTest {
-
- private final String keyword;
- private final int length;
- private KeywordsExtractor keywordsExtractor;
-
- private static final Collection VALID_STRING_KEYWORDS = Arrays.asList(new Object[][]{
- {"#RandomString", DEFAULT_STRING_LENGTH},
- {"1#RandomString2", 1 + DEFAULT_STRING_LENGTH + 1},
- {"#RandomString(23)", 23},
- {"#RandomString(11)12", 11 + 2},
- {"1#RandomString(11)", 1 + 11},
- {"1#RandomString(11)2", 1 + 11 + 1}
- });
-
- public KeywordsExtractorValidRandomStringTest(String keyword, int length) {
- this.keyword = keyword;
- this.length = length;
- }
-
- @Before
- public void setUp() {
- this.keywordsExtractor = new KeywordsExtractor();
- }
-
- @Parameterized.Parameters
- public static Collection data() {
- return VALID_STRING_KEYWORDS;
- }
-
- @Test
- public void checkValidRandomStringKeyword() {
- assertEquals(keywordsExtractor.substituteStringKeyword(this.keyword, 1).length(), this.length);
- }
-
-}
diff --git a/test/mocks/pnfsimulator/pnfsimulator/src/test/java/org/onap/pnfsimulator/simulator/KeywordsExtractorValidTimestampPrimitiveTest.java b/test/mocks/pnfsimulator/pnfsimulator/src/test/java/org/onap/pnfsimulator/simulator/KeywordsExtractorValidTimestampPrimitiveTest.java
deleted file mode 100644
index 7743e5558..000000000
--- a/test/mocks/pnfsimulator/pnfsimulator/src/test/java/org/onap/pnfsimulator/simulator/KeywordsExtractorValidTimestampPrimitiveTest.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * PNF-REGISTRATION-HANDLER
- * ================================================================================
- * Copyright (C) 2019 Nokia. All rights reserved.
- * ================================================================================
- * 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
- *
- * 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=========================================================
- */
-
-package org.onap.pnfsimulator.simulator;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
-
-import java.time.Instant;
-import java.util.Arrays;
-import java.util.Collection;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-@RunWith(Parameterized.class)
-public class KeywordsExtractorValidTimestampPrimitiveTest {
- private final String keyword;
- private KeywordsExtractor keywordsExtractor;
-
- private static final Collection VALID_TIMESTAMP_KEYWORDS = Arrays.asList(new Object[][]{
- {"#TimestampPrimitive"}
- });
-
- public KeywordsExtractorValidTimestampPrimitiveTest(String keyword) {
- this.keyword = keyword;
- }
-
- @Before
- public void setUp() {
- this.keywordsExtractor = new KeywordsExtractor();
- }
-
- @Parameterized.Parameters
- public static Collection data() {
- return VALID_TIMESTAMP_KEYWORDS;
- }
-
- @Test
- public void checkValidRandomStringKeyword() {
- long currentTimestamp = Instant.now().getEpochSecond();
- Long timestamp = keywordsExtractor.substitutePrimitiveKeyword(this.keyword);
- long afterExecution = Instant.now().getEpochSecond();
-
- assertThat(timestamp).isBetween(currentTimestamp, afterExecution);
- }
-
-}
diff --git a/test/mocks/pnfsimulator/pnfsimulator/src/test/java/org/onap/pnfsimulator/simulator/KeywordsExtractorValidTimestampTest.java b/test/mocks/pnfsimulator/pnfsimulator/src/test/java/org/onap/pnfsimulator/simulator/KeywordsExtractorValidTimestampTest.java
deleted file mode 100644
index f5c12c311..000000000
--- a/test/mocks/pnfsimulator/pnfsimulator/src/test/java/org/onap/pnfsimulator/simulator/KeywordsExtractorValidTimestampTest.java
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * PNF-REGISTRATION-HANDLER
- * ================================================================================
- * Copyright (C) 2018 Nokia. All rights reserved.
- * ================================================================================
- * 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
- *
- * 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=========================================================
- */
-
-package org.onap.pnfsimulator.simulator;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-
-import java.util.Arrays;
-import java.util.Collection;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
-
-@RunWith(Parameterized.class)
-public class KeywordsExtractorValidTimestampTest {
-
- private final String keyword;
- private final int length;
- private KeywordsExtractor keywordsExtractor;
-
- private static final Collection VALID_TIMESTAMP_KEYWORDS = Arrays.asList(new Object[][]{
- {"#Timestamp", 10},
- {"#Timestamp12", 10 + 2},
- {"1#Timestamp", 1 + 10},
- {"1#Timestamp2", 1 + 10 +1}
- });
-
- public KeywordsExtractorValidTimestampTest(String keyword, Integer length) {
- this.keyword = keyword;
- this.length = length;
- }
-
- @Before
- public void setUp() {
- this.keywordsExtractor = new KeywordsExtractor();
- }
-
- @Parameterized.Parameters
- public static Collection data() {
- return VALID_TIMESTAMP_KEYWORDS;
- }
-
- @Test
- public void checkValidRandomStringKeyword() {
- String substitution = keywordsExtractor.substituteStringKeyword(this.keyword, 1);
- assertEquals(substitution.length(), this.length);
- }
-
-}
diff --git a/test/mocks/pnfsimulator/pnfsimulator/src/test/java/org/onap/pnfsimulator/simulator/KeywordsHandlerTest.java b/test/mocks/pnfsimulator/pnfsimulator/src/test/java/org/onap/pnfsimulator/simulator/KeywordsHandlerTest.java
deleted file mode 100644
index e67d4a33b..000000000
--- a/test/mocks/pnfsimulator/pnfsimulator/src/test/java/org/onap/pnfsimulator/simulator/KeywordsHandlerTest.java
+++ /dev/null
@@ -1,304 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * PNF-REGISTRATION-HANDLER
- * ================================================================================
- * Copyright (C) 2018 Nokia. All rights reserved.
- * ================================================================================
- * 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
- *
- * 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=========================================================
- */
-
-package org.onap.pnfsimulator.simulator;
-
-import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
-import static org.onap.pnfsimulator.simulator.KeywordsValueProvider.DEFAULT_STRING_LENGTH;
-
-import com.google.gson.Gson;
-import com.google.gson.JsonElement;
-import com.google.gson.JsonObject;
-import java.util.Arrays;
-import java.util.LinkedList;
-import java.util.Queue;
-import org.junit.jupiter.api.Test;
-
-class KeywordsHandlerTest {
-
- private static final String TEMPLATE_JSON = "{\n" +
- " \"event\": {\n" +
- " \"commonEventHeader\": {\n" +
- " \"domain\": \"#RandomString\"\n" +
- " },\n" +
- " \"measurementsForVfScalingFields\": {\n" +
- " \"measurementsForVfSclaingFieldsVersion\": 2.0,\n" +
- " \"additionalMeasurements\": {\n" +
- " \"name\": \"licenseUsage\",\n" +
- " \"extraFields\": {\n" +
- " \"name\": \"#RandomString(4)\",\n" +
- " \"value\": \"1\"\n" +
- " }\n" +
- " }\n" +
- " }\n" +
- " }\n" +
- "}";
-
- private static final String TEMPLATE_JSON_WITH_MANY_KEYWORDS_INSIDE_SINGLE_VALUE = "{\n" +
- " \"event\": {\n" +
- " \"commonEventHeader\": {\n" +
- " \"domain1\": \"#RandomString(1) #RandomString(2) #RandomString(3)\",\n" +
- " \"domain2\": \"1 #RandomString(1) 2\"\n" +
- " },\n" +
- " \"measurementsForVfScalingFields\": {\n" +
- " \"measurementsForVfSclaingFieldsVersion\": 2.0,\n" +
- " \"additionalMeasurements\": {\n" +
- " \"name\": \"licenseUsage\",\n" +
- " \"extraFields\": {\n" +
- " \"value\": \"1\"\n" +
- " }\n" +
- " }\n" +
- " }\n" +
- " }\n" +
- "}";
-
- private static final String TEMPLATE_JSON_WITH_ARRAY = "{\n"
- + " \"event\": {\n"
- + " \"commonEventHeader\": {\n"
- + " \"domain\": \"#RandomString(1)\",\n"
- + " \"version\": 2.0\n"
- + " },\n"
- + " \"measurementsForVfScalingFields\": {\n"
- + " \"additionalMeasurements\": [\n"
- + " {\n"
- + " \"name\": \"licenseUsage\",\n"
- + " \"arrayOfFields\": [\n"
- + " {\n"
- + " \"name\": \"G711AudioPort\",\n"
- + " \"value\": \"1\"\n"
- + " },\n"
- + " {\n"
- + " \"name\": [\"1\",\"2\"],\n"
- + " \"value\": \"#RandomString(2)\"\n"
- + " },\n"
- + " {\n"
- + " \"name\": \"G722AudioPort\",\n"
- + " \"value\": \"1\"\n"
- + " }\n"
- + " ]\n"
- + " }\n"
- + " ]\n"
- + " }\n"
- + " }\n"
- + "}";
-
- private static final String TEMPLATE_ONE_INCREMENT_JSON = "{\n" +
- " \"event\": {\n" +
- " \"commonEventHeader\": {\n" +
- " \"domain\": \"#RandomString\"\n" +
- " },\n" +
- " \"measurementsForVfScalingFields\": {\n" +
- " \"measurementsForVfSclaingFieldsVersion\": 2.0,\n" +
- " \"additionalMeasurements\": {\n" +
- " \"name\": \"licenseUsage\",\n" +
- " \"extraFields\": {\n" +
- " \"name\": \"#RandomString(4)\",\n" +
- " \"value\": \"#Increment\"\n" +
- " }\n" +
- " }\n" +
- " }\n" +
- " }\n" +
- "}";
-
- private static final String TEMPLATE_WITH_SIMPLE_VALUE= "\"#RandomString(4)\"";
-
- private static final String TEMPLATE_WITH_ARRAY_OF_PRIMITIVES = "[ 1, \"#RandomString(5)\", 3]";
-
- private static final String TEMPLATE_TWO_INCREMENT_JSON = "{\n" +
- " \"event\": {\n" +
- " \"commonEventHeader\": {\n" +
- " \"domain\": \"#RandomString\"\n" +
- " },\n" +
- " \"measurementsForVfScalingFields\": {\n" +
- " \"measurementsForVfSclaingFieldsVersion\": 2.0,\n" +
- " \"additionalMeasurements\": {\n" +
- " \"name\": \"licenseUsage\",\n" +
- " \"extraFields\": {\n" +
- " \"name\": \"#RandomString(4)\",\n" +
- " \"value\": \"#Increment\",\n" +
- " \"otherValue\": \"#Increment\"\n" +
- " }\n" +
- " }\n" +
- " }\n" +
- " }\n" +
- "}";
-
- private Gson gson = new Gson();
-
- @Test
- void shouldReplaceRandomStringKeyword() {
- // given
- JsonObject templateJson = gson.fromJson(TEMPLATE_JSON, JsonObject.class);
- KeywordsHandler keywordsHandler = new KeywordsHandler(new KeywordsExtractor(), (id) -> 1);
-
- // when
- JsonObject resultJson = keywordsHandler.substituteKeywords(templateJson, "").getAsJsonObject();
-
- // then
- String extraFields = resultJson
- .get("event").getAsJsonObject()
- .get("measurementsForVfScalingFields").getAsJsonObject()
- .get("additionalMeasurements").getAsJsonObject()
- .get("extraFields").getAsJsonObject()
- .get("name").getAsString();
- String newDomain = resultJson
- .get("event").getAsJsonObject()
- .get("commonEventHeader").getAsJsonObject()
- .get("domain").getAsString();
-
- assertThat(extraFields.length()).isEqualTo(4);
- assertThat(newDomain.length()).isEqualTo(DEFAULT_STRING_LENGTH);
- }
-
- @Test
- void shouldReplaceRandomStringKeywordsInsideSingleValue() {
- // given
- JsonObject templateJson = gson.fromJson(TEMPLATE_JSON_WITH_MANY_KEYWORDS_INSIDE_SINGLE_VALUE, JsonObject.class);
- KeywordsHandler keywordsHandler = new KeywordsHandler(new KeywordsExtractor(), (id) -> 1);
-
- // when
- JsonObject resultJson = keywordsHandler.substituteKeywords(templateJson, "").getAsJsonObject();
-
- // then
- String newDomain1 = resultJson
- .get("event").getAsJsonObject()
- .get("commonEventHeader").getAsJsonObject()
- .get("domain1").getAsString();
- String newDomain2 = resultJson
- .get("event").getAsJsonObject()
- .get("commonEventHeader").getAsJsonObject()
- .get("domain2").getAsString();
-
- assertThat(newDomain1.length()).isEqualTo(1+1+2+1+3);
- assertThat(newDomain2.length()).isEqualTo(1+1+1+1+1);
- }
-
- @Test
- void shouldReplaceRandomStringKeywordInTeplateAsArrayWithPrimitves() {
- // given
- JsonElement templateJson = gson.fromJson(TEMPLATE_WITH_ARRAY_OF_PRIMITIVES, JsonElement.class);
- KeywordsHandler keywordsHandler = new KeywordsHandler(new KeywordsExtractor(), (id) -> 1);
-
- // when
- JsonElement resultJson = keywordsHandler.substituteKeywords(templateJson, "");
- assertThat(resultJson.getAsJsonArray().get(1).getAsString().length()).isEqualTo(5);
- }
-
- @Test
- void shouldReplaceRandomStringKeywordInTeplateAsSimpleValue() {
- // given
- JsonElement templateJson = gson.fromJson(TEMPLATE_WITH_SIMPLE_VALUE, JsonElement.class);
- KeywordsHandler keywordsHandler = new KeywordsHandler(new KeywordsExtractor(), (id) -> 1);
-
- // when
- JsonElement resultJson = keywordsHandler.substituteKeywords(templateJson, "");
-
- // then
- assertThat(resultJson.getAsString().length()).isEqualTo(4);
- }
-
- @Test
- void shouldReplaceRandomStringKeywordInTeplateWithJsonArray() {
- // given
- JsonElement templateJson = gson.fromJson(TEMPLATE_JSON_WITH_ARRAY, JsonElement.class);
- KeywordsHandler keywordsHandler = new KeywordsHandler(new KeywordsExtractor(), (id) -> 1);
-
- // when
- JsonObject resultJson = keywordsHandler.substituteKeywords(templateJson, "").getAsJsonObject();
-
- // then
- String actualValue = resultJson
- .get("event").getAsJsonObject()
- .get("measurementsForVfScalingFields").getAsJsonObject()
- .get("additionalMeasurements").getAsJsonArray()
- .get(0).getAsJsonObject()
- .get("arrayOfFields").getAsJsonArray()
- .get(1).getAsJsonObject()
- .get("value").getAsString();
- String otherActualValue = resultJson
- .get("event").getAsJsonObject()
- .get("commonEventHeader").getAsJsonObject()
- .get("domain").getAsString();
-
- assertThat(otherActualValue.length()).isEqualTo(1);
- assertThat(actualValue.length()).isEqualTo(2);
- }
-
- @Test
- void shouldReplaceOneIncrementKeyword() {
- // given
- final Integer newIncrementedValue = 2;
- JsonObject templateJson = gson.fromJson(TEMPLATE_ONE_INCREMENT_JSON, JsonObject.class);
- KeywordsHandler keywordsHandler = new KeywordsHandler(new KeywordsExtractor(), (id) -> newIncrementedValue);
-
- // when
- JsonObject resultJson = keywordsHandler.substituteKeywords(templateJson, "some random id").getAsJsonObject();
-
- // then
- String actualValue = resultJson
- .get("event").getAsJsonObject()
- .get("measurementsForVfScalingFields").getAsJsonObject()
- .get("additionalMeasurements").getAsJsonObject()
- .get("extraFields").getAsJsonObject()
- .get("value").getAsString();
-
- assertThat(actualValue).isEqualTo(newIncrementedValue.toString());
- }
-
- @Test
- void shouldReplaceTwoIncrementKeyword() {
- // given
- final Integer firstIncrementValue = 2;
- final Integer secondIncrementValue = 3;
- JsonObject templateJson = gson.fromJson(TEMPLATE_TWO_INCREMENT_JSON, JsonObject.class);
- KeywordsHandler keywordsHandler = new KeywordsHandler(new KeywordsExtractor(), new IncrementProvider() {
- Queue<Integer> sequenceOfValues = new LinkedList<>(
- Arrays.asList(firstIncrementValue, secondIncrementValue));
-
- @Override
- public int getAndIncrement(String id) {
- return sequenceOfValues.poll();
- }
- });
-
- // when
- JsonObject resultJson = keywordsHandler.substituteKeywords(templateJson, "some random id").getAsJsonObject();
- resultJson = keywordsHandler.substituteKeywords(templateJson, "some random id").getAsJsonObject();
-
- // then
- String actualValue = resultJson
- .get("event").getAsJsonObject()
- .get("measurementsForVfScalingFields").getAsJsonObject()
- .get("additionalMeasurements").getAsJsonObject()
- .get("extraFields").getAsJsonObject()
- .get("value").getAsString();
-
- String actualOtherValue = resultJson
- .get("event").getAsJsonObject()
- .get("measurementsForVfScalingFields").getAsJsonObject()
- .get("additionalMeasurements").getAsJsonObject()
- .get("extraFields").getAsJsonObject()
- .get("otherValue").getAsString();
-
- assertThat(actualValue).isEqualTo(secondIncrementValue.toString());
- assertThat(actualOtherValue).isEqualTo(secondIncrementValue.toString());
-
- }
-}
diff --git a/test/mocks/pnfsimulator/pnfsimulator/src/test/java/org/onap/pnfsimulator/simulator/KeywordsValueProviderTest.java b/test/mocks/pnfsimulator/pnfsimulator/src/test/java/org/onap/pnfsimulator/simulator/KeywordsValueProviderTest.java
deleted file mode 100644
index 73e4c31df..000000000
--- a/test/mocks/pnfsimulator/pnfsimulator/src/test/java/org/onap/pnfsimulator/simulator/KeywordsValueProviderTest.java
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * PNF-REGISTRATION-HANDLER
- * ================================================================================
- * Copyright (C) 2018 Nokia. All rights reserved.
- * ================================================================================
- * 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
- *
- * 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=========================================================
- */
-
-package org.onap.pnfsimulator.simulator;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.onap.pnfsimulator.simulator.KeywordsValueProvider.DEFAULT_STRING_LENGTH;
-
-import java.util.Random;
-import org.junit.jupiter.api.RepeatedTest;
-import org.junit.jupiter.api.Test;
-
-class KeywordsValueProviderTest {
-
- @RepeatedTest(10)
- void randomLimitedStringTest() {
- String supplierResult = KeywordsValueProvider.getRandomLimitedString().apply();
- assertEquals(supplierResult.length(), DEFAULT_STRING_LENGTH);
- }
-
- @RepeatedTest(10)
- void randomStringTest() {
- int length = new Random().nextInt(15) + 1;
- String supplierResult = KeywordsValueProvider.getRandomString().apply(length);
- assertEquals(supplierResult.length(), length);
- }
-
- @RepeatedTest(10)
- void randomIntegerTest(){
- int min = new Random().nextInt(10) + 1;
- int max = new Random().nextInt(1000) + 20;
- String supplierResult = KeywordsValueProvider.getRandomInteger().apply(min, max);
- assertTrue(Integer.parseInt(supplierResult)>=min);
- assertTrue(Integer.parseInt(supplierResult)<=max);
- }
-
- @Test
- void randomIntegerContainsMaximalAndMinimalValuesTest(){
- int anyNumber = new Random().nextInt(10) + 1;
- String supplierResult = KeywordsValueProvider.getRandomInteger().apply(anyNumber, anyNumber);
- assertEquals(Integer.parseInt(supplierResult), anyNumber);
- }
-
- @Test
- void randomIntegerFromNegativeRangeTest(){
- String supplierResult = KeywordsValueProvider.getRandomInteger().apply(-20, -20);
- assertEquals(Integer.parseInt(supplierResult), -20);
- }
-
- @RepeatedTest(10)
- void randomIntegerFromParametersWithDifferentOrdersTest(){
- String supplierResult = KeywordsValueProvider.getRandomInteger().apply(-20, -10);
- assertTrue(Integer.parseInt(supplierResult)>=-20);
- assertTrue(Integer.parseInt(supplierResult)<=-10);
- }
-
- @RepeatedTest(10)
- void epochSecondGeneratedInCorrectFormatTest(){
- String supplierResult = KeywordsValueProvider.getEpochSecond().apply();
- assertEquals(supplierResult.length(), 10);
- }
-
-}
diff --git a/test/mocks/pnfsimulator/pnfsimulator/src/test/java/org/onap/pnfsimulator/simulator/SimulatorServiceTest.java b/test/mocks/pnfsimulator/pnfsimulator/src/test/java/org/onap/pnfsimulator/simulator/SimulatorServiceTest.java
deleted file mode 100644
index 32dd532aa..000000000
--- a/test/mocks/pnfsimulator/pnfsimulator/src/test/java/org/onap/pnfsimulator/simulator/SimulatorServiceTest.java
+++ /dev/null
@@ -1,226 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * PNF-REGISTRATION-HANDLER
- * ================================================================================
- * Copyright (C) 2018 Nokia. All rights reserved.
- * ================================================================================
- * 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
- *
- * 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=========================================================
- */
-
-package org.onap.pnfsimulator.simulator;
-
-import com.google.gson.Gson;
-import com.google.gson.JsonElement;
-import com.google.gson.JsonObject;
-import com.google.gson.JsonSyntaxException;
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
-import org.mockito.ArgumentCaptor;
-import org.onap.pnfsimulator.event.EventData;
-import org.onap.pnfsimulator.event.EventDataService;
-import org.onap.pnfsimulator.rest.model.FullEvent;
-import org.onap.pnfsimulator.rest.model.SimulatorParams;
-import org.onap.pnfsimulator.rest.model.SimulatorRequest;
-import org.onap.pnfsimulator.simulator.client.HttpClientAdapter;
-import org.onap.pnfsimulator.simulator.scheduler.EventScheduler;
-import org.onap.pnfsimulator.simulatorconfig.SimulatorConfig;
-import org.onap.pnfsimulator.simulatorconfig.SimulatorConfigService;
-import org.quartz.SchedulerException;
-
-import java.io.IOException;
-import java.net.MalformedURLException;
-import java.net.URL;
-
-import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat;
-import static org.junit.jupiter.api.Assertions.assertThrows;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.doNothing;
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-import static org.mockito.internal.verification.VerificationModeFactory.times;
-
-class SimulatorServiceTest {
-
- private static final String VES_URL = "http://0.0.0.0:8080";
- private static final Gson GSON = new Gson();
- private static final JsonObject VALID_PATCH = GSON.fromJson("{\"event\": {\n" +
- " \"commonEventHeader\": {\n" +
- " \"sourceName\": \"SomeCustomSource\"}}}\n", JsonObject.class);
- private static JsonObject VALID_FULL_EVENT = GSON.fromJson("{\"event\": {\n" +
- " \"commonEventHeader\": {\n" +
- " \"domain\": \"notification\",\n" +
- " \"eventName\": \"vFirewallBroadcastPackets\"\n" +
- " },\n" +
- " \"notificationFields\": {\n" +
- " \"arrayOfNamedHashMap\": [{\n" +
- " \"name\": \"A20161221.1031-1041.bin.gz\",\n" +
- " \"hashMap\": {\n" +
- " \"fileformatType\": \"org.3GPP.32.435#measCollec\"}}]}}}", JsonObject.class);
- private static JsonObject FULL_EVENT_WITH_KEYWORDS = GSON.fromJson("{\"event\":{ \n" +
- " \"commonEventHeader\":{ \n" +
- " \"domain\":\"notification\",\n" +
- " \"eventName\":\"#RandomString(20)\",\n" +
- " \"eventOrderNo\":\"#Increment\"}}}", JsonObject.class);
- private static final String SOME_CUSTOM_SOURCE = "SomeCustomSource";
- private static final String CLOSED_LOOP_VNF ="ClosedLoopVNF";
- private static final String SAMPLE_ID = "sampleId";
- private static final EventData SAMPLE_EVENT = EventData.builder().id("1").build();
- private final ArgumentCaptor<JsonObject> bodyCaptor = ArgumentCaptor.forClass(JsonObject.class);
- private final ArgumentCaptor<Integer> intervalCaptor = ArgumentCaptor.forClass(Integer.class);
- private final ArgumentCaptor<Integer> repeatCountCaptor = ArgumentCaptor
- .forClass(Integer.class);
- private final ArgumentCaptor<String> templateNameCaptor = ArgumentCaptor.forClass(String.class);
- private final ArgumentCaptor<String> eventIdCaptor = ArgumentCaptor.forClass(String.class);
- private final ArgumentCaptor<String> vesUrlCaptor = ArgumentCaptor.forClass(String.class);
- private final ArgumentCaptor<String> eventContentCaptor = ArgumentCaptor.forClass(String.class);
- private SimulatorService simulatorService;
- private EventDataService eventDataService;
- private EventScheduler eventScheduler;
- private SimulatorConfigService simulatorConfigService;
- private static TemplatePatcher templatePatcher = new TemplatePatcher();
- private static TemplateReader templateReader = new FilesystemTemplateReader(
- "src/test/resources/org/onap/pnfsimulator/simulator/", GSON);
-
- @BeforeEach
- void setUp() {
- eventDataService = mock(EventDataService.class);
- eventScheduler = mock(EventScheduler.class);
- simulatorConfigService = mock(SimulatorConfigService.class);
-
- simulatorService = new SimulatorService(templatePatcher, templateReader,
- eventScheduler, eventDataService, simulatorConfigService);
- }
-
- @Test
- void shouldTriggerEventWithGivenParams() throws IOException, SchedulerException {
- String templateName = "validExampleMeasurementEvent.json";
- SimulatorParams simulatorParams = new SimulatorParams(VES_URL, 1, 1);
- SimulatorRequest simulatorRequest = new SimulatorRequest(simulatorParams,
- templateName, VALID_PATCH);
-
- doReturn(SAMPLE_EVENT).when(eventDataService).persistEventData(any(JsonObject.class), any(JsonObject.class), any(JsonObject.class), any(JsonObject.class));
-
- simulatorService.triggerEvent(simulatorRequest);
-
- assertEventHasExpectedStructure(VES_URL, templateName, SOME_CUSTOM_SOURCE);
- }
-
- @Test
- void shouldTriggerEventWithDefaultVesUrlWhenNotProvidedInRequest() throws IOException, SchedulerException {
- String templateName = "validExampleMeasurementEvent.json";
- SimulatorRequest simulatorRequest = new SimulatorRequest(
- new SimulatorParams("", 1, 1),
- templateName, VALID_PATCH);
-
- URL inDbVesUrl = new URL("http://0.0.0.0:8080/eventListener/v6");
- doReturn(SAMPLE_EVENT).when(eventDataService).persistEventData(any(JsonObject.class), any(JsonObject.class), any(JsonObject.class), any(JsonObject.class));
- when(simulatorConfigService.getConfiguration()).thenReturn(new SimulatorConfig(SAMPLE_ID, inDbVesUrl));
-
- simulatorService.triggerEvent(simulatorRequest);
-
- assertEventHasExpectedStructure(inDbVesUrl.toString(), templateName, SOME_CUSTOM_SOURCE);
- }
-
- @Test
- void shouldThrowJsonSyntaxWhenInvalidJson() {
- //given
- JsonObject patch = GSON.fromJson("{\n" +
- " \"event\": {\n" +
- " \"commonEventHeader\": {\n" +
- " \"sourceName\": \"" + SOME_CUSTOM_SOURCE + "\"\n" +
- " }\n" +
- " }\n" +
- "}\n", JsonObject.class);
- EventData eventData = EventData.builder().id("1").build();
-
- SimulatorParams simulatorParams = new SimulatorParams(VES_URL, 1, 1);
- SimulatorRequest simulatorRequest = new SimulatorRequest(simulatorParams,
- "invalidJsonStructureEvent.json", patch);
- doReturn(eventData).when(eventDataService).persistEventData(any(JsonObject.class), any(JsonObject.class), any(JsonObject.class), any(JsonObject.class));
-
- //when
- assertThrows(JsonSyntaxException.class,
- () -> simulatorService.triggerEvent(simulatorRequest));
- }
-
- @Test
- void shouldHandleNonExistingPatchSection() throws IOException, SchedulerException {
- String templateName = "validExampleMeasurementEvent.json";
- JsonObject nullPatch = null;
- SimulatorRequest simulatorRequest = new SimulatorRequest(
- new SimulatorParams("", 1, 1),
- templateName, nullPatch);
-
- URL inDbVesUrl = new URL("http://0.0.0.0:8080/eventListener/v6");
- doReturn(SAMPLE_EVENT).when(eventDataService).persistEventData(any(JsonObject.class), any(JsonObject.class), any(JsonObject.class), any(JsonObject.class));
- doReturn(new SimulatorConfig(SAMPLE_ID, inDbVesUrl)).when(simulatorConfigService).getConfiguration();
-
- simulatorService.triggerEvent(simulatorRequest);
-
- assertEventHasExpectedStructure(inDbVesUrl.toString(), templateName, CLOSED_LOOP_VNF);
- }
-
- @Test
- void shouldSuccessfullySendOneTimeEventWithVesUrlWhenPassed() throws MalformedURLException {
- SimulatorService spiedTestedService = spy(new SimulatorService(templatePatcher,templateReader, eventScheduler, eventDataService, simulatorConfigService));
-
- HttpClientAdapter adapterMock = mock(HttpClientAdapter.class);
- doNothing().when(adapterMock).send(eventContentCaptor.capture());
- doReturn(adapterMock).when(spiedTestedService).createHttpClientAdapter(any(String.class));
- FullEvent event = new FullEvent(VES_URL, VALID_FULL_EVENT);
-
- spiedTestedService.triggerOneTimeEvent(event);
-
- assertThat(eventContentCaptor.getValue()).isEqualTo(VALID_FULL_EVENT.toString());
- verify(eventDataService, times(1)).persistEventData(any(JsonObject.class), any(JsonObject.class), any(JsonObject.class), any(JsonObject.class));
- verify(adapterMock, times(1)).send(VALID_FULL_EVENT.toString());
- }
-
- @Test
- void shouldSubstituteKeywordsAndSuccessfullySendOneTimeEvent() throws MalformedURLException {
- SimulatorService spiedTestedService = spy(new SimulatorService(templatePatcher,templateReader, eventScheduler, eventDataService, simulatorConfigService));
-
- HttpClientAdapter adapterMock = mock(HttpClientAdapter.class);
- doNothing().when(adapterMock).send(eventContentCaptor.capture());
- doReturn(adapterMock).when(spiedTestedService).createHttpClientAdapter(any(String.class));
- FullEvent event = new FullEvent(VES_URL, FULL_EVENT_WITH_KEYWORDS);
-
- spiedTestedService.triggerOneTimeEvent(event);
-
- JsonObject sentContent = GSON.fromJson(eventContentCaptor.getValue(), JsonElement.class).getAsJsonObject();
- assertThat(sentContent.getAsJsonObject("event").getAsJsonObject("commonEventHeader").get("eventOrderNo").getAsString()).isEqualTo("1");
- assertThat(sentContent.getAsJsonObject("event").getAsJsonObject("commonEventHeader").get("eventName").getAsString()).hasSize(20);
- }
-
-
- private void assertEventHasExpectedStructure(String expectedVesUrl, String templateName, String sourceNameString) throws SchedulerException, MalformedURLException {
- verify(eventScheduler, times(1)).scheduleEvent(vesUrlCaptor.capture(), intervalCaptor.capture(),
- repeatCountCaptor.capture(), templateNameCaptor.capture(), eventIdCaptor.capture(), bodyCaptor.capture());
- assertThat(vesUrlCaptor.getValue()).isEqualTo(expectedVesUrl);
- assertThat(intervalCaptor.getValue()).isEqualTo(1);
- assertThat(repeatCountCaptor.getValue()).isEqualTo(1);
- assertThat(templateNameCaptor.getValue()).isEqualTo(templateName);
- String actualSourceName = GSON.fromJson(bodyCaptor.getValue(), JsonObject.class)
- .get("event").getAsJsonObject()
- .get("commonEventHeader").getAsJsonObject()
- .get("sourceName").getAsString();
- assertThat(actualSourceName).isEqualTo(sourceNameString);
- verify(eventDataService)
- .persistEventData(any(JsonObject.class), any(JsonObject.class), any(JsonObject.class),
- any(JsonObject.class));
- }
-}
diff --git a/test/mocks/pnfsimulator/pnfsimulator/src/test/java/org/onap/pnfsimulator/simulator/TemplatePatcherTest.java b/test/mocks/pnfsimulator/pnfsimulator/src/test/java/org/onap/pnfsimulator/simulator/TemplatePatcherTest.java
deleted file mode 100644
index 52e0d6ae6..000000000
--- a/test/mocks/pnfsimulator/pnfsimulator/src/test/java/org/onap/pnfsimulator/simulator/TemplatePatcherTest.java
+++ /dev/null
@@ -1,164 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * PNF-REGISTRATION-HANDLER
- * ================================================================================
- * Copyright (C) 2018 Nokia. All rights reserved.
- * ================================================================================
- * 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
- *
- * 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=========================================================
- */
-
-package org.onap.pnfsimulator.simulator;
-
-import com.google.gson.Gson;
-import com.google.gson.JsonElement;
-import com.google.gson.JsonObject;
-import org.assertj.core.api.AssertionsForInterfaceTypes;
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
-
-import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
-
-class TemplatePatcherTest {
-
- private static final String TEMPLATE_JSON = "{\n" +
- " \"event\": {\n" +
- " \"commonEventHeader\": {\n" +
- " \"domain\": \"measurementsForVfScaling\"\n" +
- " },\n" +
- " \"measurementsForVfScalingFields\": {\n" +
- " \"measurementsForVfSclaingFieldsVersion\": 2.0,\n" +
- " \"additionalMeasurements\": {\n" +
- " \"name\": \"licenseUsage\",\n" +
- " \"extraFields\": {\n" +
- " \"name\": \"G711AudioPort\",\n" +
- " \"value\": \"1\"\n" +
- " }\n" +
- " }\n" +
- " }\n" +
- " }\n" +
- "}";
-
- private TemplatePatcher templatePatcher;
- private Gson gson = new Gson();
- private JsonObject templateJson;
-
- @BeforeEach
- void setUp() {
- templatePatcher = new TemplatePatcher();
- templateJson = gson.fromJson(TEMPLATE_JSON, JsonObject.class);
- }
-
- @Test
- void shouldReplaceJsonElementsInTemplate() {
- //given
- String patchJsonString = "{\n"
- + " \"event\": {\n"
- + " \"commonEventHeader\": {\n"
- + " \"domain\": \"newDomain\"\n"
- + " }\n"
- + " }\n"
- + "}";
- JsonObject patchJson = gson.fromJson(patchJsonString, JsonObject.class);
-
- //when
- JsonObject requestJson = templatePatcher.mergeTemplateWithPatch(templateJson, patchJson);
-
- //then
- String newDomain = requestJson
- .get("event").getAsJsonObject()
- .get("commonEventHeader").getAsJsonObject()
- .get("domain").getAsString();
- assertThat(newDomain).isEqualTo("newDomain");
- }
-
- @Test
- void shouldAddWholeJsonObjectToTemplateWhenItFinished() {
- //given
- String patchJsonString =
- "{\n"
- + " \"event\": {\n"
- + " \"commonEventHeader\": {\n"
- + " \"domain\": {\n"
- + " \"extraFields\": {\n"
- + " \"name\": \"G711AudioPort\",\n"
- + " \"value\": \"1\"\n"
- + " }\n"
- + " }\n"
- + " }\n"
- + " }\n"
- + "}";
- JsonObject patchJson = gson.fromJson(patchJsonString, JsonObject.class);
-
- //when
- JsonObject requestJson = templatePatcher.mergeTemplateWithPatch(templateJson, patchJson);
-
- //then
- JsonElement newDomain = requestJson
- .get("event").getAsJsonObject()
- .get("commonEventHeader").getAsJsonObject()
- .get("domain");
- assertThat(newDomain.isJsonObject()).isTrue();
- JsonObject newDomainJO = newDomain.getAsJsonObject();
- AssertionsForInterfaceTypes.assertThat(newDomainJO.keySet()).containsExactly("extraFields");
- JsonObject newDomainExtraFields = newDomainJO.get("extraFields").getAsJsonObject();
- AssertionsForInterfaceTypes.assertThat(newDomainExtraFields.keySet()).containsExactly("name", "value");
- }
-
- @Test
- void shouldReplaceJsonObjectWithJsonElementFromPatch() {
- //given
- String patchJsonString = "{ \"event\": \"test\" }";
- JsonObject patchJson = gson.fromJson(patchJsonString, JsonObject.class);
-
- //when
- JsonObject requestJson = templatePatcher.mergeTemplateWithPatch(templateJson, patchJson);
-
- //then
- assertThat(requestJson.get("event").isJsonObject()).isFalse();
- assertThat(requestJson.get("event").getAsString()).isEqualTo("test");
- }
-
- @Test
- void shouldAddNewKeyIfPatchHasItAndTempleteDoesnt() {
- //given
- String patchJsonString = "{ \"newTestKey\": { \"newTestKeyChild\":\"newTestValue\" }}";
- JsonObject patchJson = gson.fromJson(patchJsonString, JsonObject.class);
-
- //when
- JsonObject requestJson = templatePatcher.mergeTemplateWithPatch(templateJson, patchJson);
-
- //then
- assertThat(requestJson.get("event").isJsonObject()).isTrue();
- assertThat(requestJson.get("newTestKey").isJsonObject()).isTrue();
- JsonObject newTestKey = requestJson.get("newTestKey").getAsJsonObject();
- AssertionsForInterfaceTypes.assertThat(newTestKey.keySet()).containsExactly("newTestKeyChild");
- assertThat(newTestKey.get("newTestKeyChild").getAsString()).isEqualTo("newTestValue");
-
- }
-
-
- @Test
- void shouldNotChangeInputTemplateParam() {
- //given
- String patchJsonString = "{ \"newTestKey\": { \"newTestKeyChild\":\"newTestValue\" }}";
- JsonObject patchJson = gson.fromJson(patchJsonString, JsonObject.class);
-
- //when
- templatePatcher.mergeTemplateWithPatch(templateJson, patchJson);
-
- //then
- assertThat(templateJson).isEqualTo(gson.fromJson(TEMPLATE_JSON, JsonObject.class));
-
- }
-}
diff --git a/test/mocks/pnfsimulator/pnfsimulator/src/test/java/org/onap/pnfsimulator/simulator/TemplateReaderTest.java b/test/mocks/pnfsimulator/pnfsimulator/src/test/java/org/onap/pnfsimulator/simulator/TemplateReaderTest.java
deleted file mode 100644
index f029fce75..000000000
--- a/test/mocks/pnfsimulator/pnfsimulator/src/test/java/org/onap/pnfsimulator/simulator/TemplateReaderTest.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * PNF-REGISTRATION-HANDLER
- * ================================================================================
- * Copyright (C) 2018 Nokia. All rights reserved.
- * ================================================================================
- * 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
- *
- * 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=========================================================
- */
-
-package org.onap.pnfsimulator.simulator;
-
-import com.google.gson.Gson;
-import com.google.gson.JsonObject;
-import com.google.gson.JsonSyntaxException;
-import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.Test;
-import org.springframework.test.context.TestPropertySource;
-
-import java.io.IOException;
-
-import static org.assertj.core.api.Java6Assertions.assertThat;
-
-@TestPropertySource
-class TemplateReaderTest {
-
- private FilesystemTemplateReader templateReader = new FilesystemTemplateReader("src/test/resources/org/onap/pnfsimulator/simulator/", new Gson());
-
- @Test
- void testShouldReadJsonFromFile() throws IOException {
- JsonObject readJson = templateReader.readTemplate("validExampleMeasurementEvent.json");
- assertThat(readJson.keySet()).containsOnly("event");
- assertThat(readJson.get("event").getAsJsonObject().keySet()).containsExactlyInAnyOrder("commonEventHeader", "measurementsForVfScalingFields");
- }
-
- @Test
- void testShouldRaiseExceptionWhenInvalidJsonIsRead() {
- Assertions.assertThrows(JsonSyntaxException.class, () -> templateReader.readTemplate("invalidJsonStructureEvent.json"));
- }
-
-}
diff --git a/test/mocks/pnfsimulator/pnfsimulator/src/test/java/org/onap/pnfsimulator/simulator/client/HttpClientAdapterImplTest.java b/test/mocks/pnfsimulator/pnfsimulator/src/test/java/org/onap/pnfsimulator/simulator/client/HttpClientAdapterImplTest.java
deleted file mode 100644
index 41bd7b1e6..000000000
--- a/test/mocks/pnfsimulator/pnfsimulator/src/test/java/org/onap/pnfsimulator/simulator/client/HttpClientAdapterImplTest.java
+++ /dev/null
@@ -1,97 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * PNF-REGISTRATION-HANDLER
- * ================================================================================
- * Copyright (C) 2018 Nokia. All rights reserved.
- * ================================================================================
- * 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
- *
- * 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=========================================================
- */
-
-package org.onap.pnfsimulator.simulator.client;
-
-import org.apache.http.HttpResponse;
-import org.apache.http.client.HttpClient;
-import org.apache.http.conn.socket.PlainConnectionSocketFactory;
-import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
-
-import java.io.IOException;
-import java.net.MalformedURLException;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.jupiter.api.Assertions.assertThrows;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-
-class HttpClientAdapterImplTest {
-
- private static final String HTTPS_URL = "https://0.0.0.0:8443/";
- private static final String HTTP_URL = "http://0.0.0.0:8000/";
-
- private HttpClient httpClient;
- private HttpResponse httpResponse;
-
- @BeforeEach
- void setup() {
- httpClient = mock(HttpClient.class);
- httpResponse = mock(HttpResponse.class);
- }
-
- @Test
- void sendShouldSuccessfullySendRequestGivenValidUrl() throws IOException {
- assertAdapterSentRequest("http://valid-url:8080");
- }
-
- @Test
- void sendShouldSuccessfullySendRequestGivenValidUrlUsingHTTPS() throws IOException {
- assertAdapterSentRequest("https://valid-url:8443");
- }
-
- @Test
- void shouldThrowExceptionWhenMalformedVesUrlPassed(){
- assertThrows(MalformedURLException.class, () -> new HttpClientAdapterImpl("http://blablabla:VES-PORT"));
- }
- @Test
- void shouldCreateAdapterWithClientNotSupportingSSLConnection() throws MalformedURLException {
- HttpClientAdapter adapterWithHttps = new HttpClientAdapterImpl(HTTPS_URL);
- try {
- adapterWithHttps.send("sample");
- } catch (Exception actualException) {
- assertThat(actualException).hasStackTraceContaining(SSLConnectionSocketFactory.class.toString());
- }
- }
-
- @Test
- void shouldCreateAdapterWithClientSupportingPlainConnectionOnly() throws MalformedURLException {
- HttpClientAdapter adapterWithHttps = new HttpClientAdapterImpl(HTTP_URL);
- try {
- adapterWithHttps.send("sample");
- } catch (Exception actualException) {
- assertThat(actualException).hasStackTraceContaining(PlainConnectionSocketFactory.class.toString());
- }
- }
-
- private void assertAdapterSentRequest(String targetUrl) throws IOException {
- HttpClientAdapter adapter = new HttpClientAdapterImpl(httpClient, targetUrl);
- doReturn(httpResponse).when(httpClient).execute(any());
-
- adapter.send("test-msg");
-
- verify(httpClient).execute(any());
- verify(httpResponse).getStatusLine();
- }
-}
diff --git a/test/mocks/pnfsimulator/pnfsimulator/src/test/java/org/onap/pnfsimulator/simulator/client/utils/ssl/SslSupportLevelTest.java b/test/mocks/pnfsimulator/pnfsimulator/src/test/java/org/onap/pnfsimulator/simulator/client/utils/ssl/SslSupportLevelTest.java
deleted file mode 100644
index ff41c441d..000000000
--- a/test/mocks/pnfsimulator/pnfsimulator/src/test/java/org/onap/pnfsimulator/simulator/client/utils/ssl/SslSupportLevelTest.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * PNF-REGISTRATION-HANDLER
- * ================================================================================
- * Copyright (C) 2018 Nokia. All rights reserved.
- * ================================================================================
- * 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
- *
- * 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=========================================================
- */
-
-package org.onap.pnfsimulator.simulator.client.utils.ssl;
-
-import org.junit.jupiter.api.Test;
-
-import java.net.MalformedURLException;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertThrows;
-
-class SslSupportLevelTest {
-
- private static final String HTTPS_URL = "https://127.0.0.1:8443/";
- private static final String HTTP_URL = "http://127.0.0.1:8080/";
-
- @Test
- void testShouldReturnAlwaysTrustSupportLevelForHttpsUrl() throws MalformedURLException {
- SslSupportLevel actualSupportLevel = SslSupportLevel.getSupportLevelBasedOnProtocol(HTTPS_URL);
- assertEquals(actualSupportLevel, SslSupportLevel.ALWAYS_TRUST);
- }
-
- @Test
- void testShouldReturnNoneSupportLevelForHttpUrl() throws MalformedURLException {
- SslSupportLevel actualSupportLevel = SslSupportLevel.getSupportLevelBasedOnProtocol(HTTP_URL);
- assertEquals(actualSupportLevel, SslSupportLevel.NONE);
- }
-
- @Test
- void testShouldRaiseExceptionWhenInvalidUrlPassed(){
- assertThrows(MalformedURLException.class, () -> SslSupportLevel.getSupportLevelBasedOnProtocol("http://bla:VES-PORT/"));
- }
-
-}
diff --git a/test/mocks/pnfsimulator/pnfsimulator/src/test/java/org/onap/pnfsimulator/simulator/scheduler/EventJobTest.java b/test/mocks/pnfsimulator/pnfsimulator/src/test/java/org/onap/pnfsimulator/simulator/scheduler/EventJobTest.java
deleted file mode 100644
index 25ed84c43..000000000
--- a/test/mocks/pnfsimulator/pnfsimulator/src/test/java/org/onap/pnfsimulator/simulator/scheduler/EventJobTest.java
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * PNF-REGISTRATION-HANDLER
- * ================================================================================
- * Copyright (C) 2018 Nokia. All rights reserved.
- * ================================================================================
- * 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
- *
- * 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=========================================================
- */
-
-package org.onap.pnfsimulator.simulator.scheduler;
-
-import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-import static org.onap.pnfsimulator.simulator.scheduler.EventJob.BODY;
-import static org.onap.pnfsimulator.simulator.scheduler.EventJob.CLIENT_ADAPTER;
-import static org.onap.pnfsimulator.simulator.scheduler.EventJob.EVENT_ID;
-import static org.onap.pnfsimulator.simulator.scheduler.EventJob.KEYWORDS_HANDLER;
-import static org.onap.pnfsimulator.simulator.scheduler.EventJob.TEMPLATE_NAME;
-import static org.onap.pnfsimulator.simulator.scheduler.EventJob.VES_URL;
-
-import com.google.gson.JsonObject;
-import com.google.gson.JsonParser;
-import org.junit.jupiter.api.Test;
-import org.mockito.ArgumentCaptor;
-import org.onap.pnfsimulator.simulator.KeywordsExtractor;
-import org.onap.pnfsimulator.simulator.KeywordsHandler;
-import org.onap.pnfsimulator.simulator.client.HttpClientAdapter;
-import org.quartz.JobDataMap;
-import org.quartz.JobDetail;
-import org.quartz.JobExecutionContext;
-import org.quartz.JobKey;
-
-class EventJobTest {
-
- @Test
- void shouldSendEventWhenExecuteCalled() {
- //given
- EventJob eventJob = new EventJob();
- String templateName = "template name";
- String vesUrl = "http://someurl:80/";
- String eventId = "1";
- JsonParser parser = new JsonParser();
- JsonObject body = parser.parse("{\"a\": \"A\"}").getAsJsonObject();
- HttpClientAdapter clientAdapter = mock(HttpClientAdapter.class);
- JobExecutionContext jobExecutionContext =
- createMockJobExecutionContext(templateName, eventId, vesUrl, body, clientAdapter);
-
- ArgumentCaptor<String> vesUrlCaptor = ArgumentCaptor.forClass(String.class);
- ArgumentCaptor<String> bodyCaptor = ArgumentCaptor.forClass(String.class);
-
- //when
- eventJob.execute(jobExecutionContext);
-
- //then
- verify(clientAdapter).send(bodyCaptor.capture());
- assertThat(bodyCaptor.getValue()).isEqualTo(body.toString());
- }
-
- private JobExecutionContext createMockJobExecutionContext(String templateName, String eventId, String vesURL,
- JsonObject body, HttpClientAdapter clientAdapter) {
-
- JobDataMap jobDataMap = new JobDataMap();
- jobDataMap.put(TEMPLATE_NAME, templateName);
- jobDataMap.put(KEYWORDS_HANDLER, new KeywordsHandler(new KeywordsExtractor(), (id) -> 1));
- jobDataMap.put(EVENT_ID, eventId);
- jobDataMap.put(VES_URL, vesURL);
- jobDataMap.put(BODY, body);
- jobDataMap.put(CLIENT_ADAPTER, clientAdapter);
-
- JobExecutionContext jobExecutionContext = mock(JobExecutionContext.class);
- JobDetail jobDetail = mock(JobDetail.class);
- when(jobExecutionContext.getJobDetail()).thenReturn(jobDetail);
- when(jobDetail.getJobDataMap()).thenReturn(jobDataMap);
- when(jobDetail.getKey()).thenReturn(new JobKey("jobId", "group"));
- return jobExecutionContext;
- }
-}
diff --git a/test/mocks/pnfsimulator/pnfsimulator/src/test/java/org/onap/pnfsimulator/simulator/scheduler/EventSchedulerTest.java b/test/mocks/pnfsimulator/pnfsimulator/src/test/java/org/onap/pnfsimulator/simulator/scheduler/EventSchedulerTest.java
deleted file mode 100644
index 9d0f7d84f..000000000
--- a/test/mocks/pnfsimulator/pnfsimulator/src/test/java/org/onap/pnfsimulator/simulator/scheduler/EventSchedulerTest.java
+++ /dev/null
@@ -1,143 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * PNF-REGISTRATION-HANDLER
- * ================================================================================
- * Copyright (C) 2018 Nokia. All rights reserved.
- * ================================================================================
- * 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
- *
- * 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=========================================================
- */
-
-package org.onap.pnfsimulator.simulator.scheduler;
-
-import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-import com.google.gson.JsonObject;
-
-import java.net.MalformedURLException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
-import org.mockito.ArgumentCaptor;
-import org.mockito.InjectMocks;
-import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
-import org.quartz.JobDataMap;
-import org.quartz.JobDetail;
-import org.quartz.JobExecutionContext;
-import org.quartz.JobKey;
-import org.quartz.Scheduler;
-import org.quartz.SchedulerException;
-import org.quartz.SimpleTrigger;
-
-class EventSchedulerTest {
-
- @InjectMocks
- EventScheduler eventScheduler;
-
- @Mock
- Scheduler quartzScheduler;
-
- @BeforeEach
- void setUp() {
- MockitoAnnotations.initMocks(this);
- }
-
- @Test
- void shouldTriggerEventWithGivenConfiguration() throws SchedulerException, MalformedURLException {
- //given
- ArgumentCaptor<JobDetail> jobDetailCaptor = ArgumentCaptor.forClass(JobDetail.class);
- ArgumentCaptor<SimpleTrigger> triggerCaptor = ArgumentCaptor.forClass(SimpleTrigger.class);
-
- String vesUrl = "http://some:80/";
- int repeatInterval = 1;
- int repeatCount = 4;
- String testName = "testName";
- String eventId = "1";
- JsonObject body = new JsonObject();
-
- //when
- eventScheduler.scheduleEvent(vesUrl, repeatInterval, repeatCount, testName, eventId, body);
-
- //then
- verify(quartzScheduler).scheduleJob(jobDetailCaptor.capture(), triggerCaptor.capture());
- JobDataMap actualJobDataMap = jobDetailCaptor.getValue().getJobDataMap();
- assertThat(actualJobDataMap.get(EventJob.BODY)).isEqualTo(body);
- assertThat(actualJobDataMap.get(EventJob.TEMPLATE_NAME)).isEqualTo(testName);
- assertThat(actualJobDataMap.get(EventJob.VES_URL)).isEqualTo(vesUrl);
-
- SimpleTrigger actualTrigger = triggerCaptor.getValue();
- // repeat count adds 1 to given value
- assertThat(actualTrigger.getRepeatCount()).isEqualTo(repeatCount - 1);
-
- //getRepeatInterval returns interval in ms
- assertThat(actualTrigger.getRepeatInterval()).isEqualTo(repeatInterval * 1000);
- }
-
- @Test
- void shouldCancelAllEvents() throws SchedulerException {
- //given
- List<JobKey> jobsKeys = Arrays.asList(new JobKey("jobName1"), new JobKey("jobName2"),
- new JobKey("jobName3"), new JobKey("jobName4"));
- List<JobExecutionContext> jobExecutionContexts = createExecutionContextWithKeys(jobsKeys);
- when(quartzScheduler.getCurrentlyExecutingJobs()).thenReturn(jobExecutionContexts);
- when(quartzScheduler.deleteJobs(jobsKeys)).thenReturn(true);
-
- //when
- boolean isCancelled = eventScheduler.cancelAllEvents();
-
- //then
- assertThat(isCancelled).isTrue();
- }
-
- @Test
- void shouldCancelSingleEvent() throws SchedulerException {
- //given
- JobKey jobToRemove = new JobKey("jobName3");
- List<JobKey> jobsKeys = Arrays.asList(new JobKey("jobName1"), new JobKey("jobName2"),
- jobToRemove, new JobKey("jobName4"));
- List<JobExecutionContext> jobExecutionContexts = createExecutionContextWithKeys(jobsKeys);
-
- when(quartzScheduler.getCurrentlyExecutingJobs()).thenReturn(jobExecutionContexts);
- when(quartzScheduler.deleteJob(jobToRemove)).thenReturn(true);
-
- //when
- boolean isCancelled = eventScheduler.cancelEvent("jobName3");
-
- //then
- assertThat(isCancelled).isTrue();
- }
-
- private List<JobExecutionContext> createExecutionContextWithKeys(List<JobKey> jobsKeys) {
- List<JobExecutionContext> contexts = new ArrayList<>();
- for (JobKey key : jobsKeys) {
- contexts.add(createExecutionContextFromKey(key));
- }
- return contexts;
- }
-
- private JobExecutionContext createExecutionContextFromKey(JobKey key) {
- JobExecutionContext context = mock(JobExecutionContext.class);
- JobDetail jobDetail = mock(JobDetail.class);
- when(context.getJobDetail()).thenReturn(jobDetail);
- when(jobDetail.getKey()).thenReturn(key);
- return context;
- }
-
-
-}