summaryrefslogtreecommitdiffstats
path: root/vid-app-common/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'vid-app-common/src/test')
-rw-r--r--vid-app-common/src/test/java/org/onap/aai/util/JettyObfuscationConversionCommandLineUtilTest.java55
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/aai/PombaClientImplTest.java15
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/model/CategoryParameterOptionTest.java186
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/model/CategoryParameterTest.java186
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/mso/MsoBusinessLogicImplTest.java6
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/mso/MsoResponseWrapper2Test.java83
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/mso/MsoResponseWrapperTest.java27
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/mso/RestObjectTest.java20
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/mso/model/OperationalEnvironmentActivateInfoTest.java67
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/mso/model/OperationalEnvironmentDeactivateInfoTest.java44
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/services/ExternalWorkflowServiceImplTest.java (renamed from vid-app-common/src/test/java/org/onap/vid/services/ExtWorkflowServiceImplTest.java)14
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/services/JobsBrokerServiceTest.java60
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/testUtils/TestUtils.java48
13 files changed, 322 insertions, 489 deletions
diff --git a/vid-app-common/src/test/java/org/onap/aai/util/JettyObfuscationConversionCommandLineUtilTest.java b/vid-app-common/src/test/java/org/onap/aai/util/JettyObfuscationConversionCommandLineUtilTest.java
index 98be994fa..e06805cc1 100644
--- a/vid-app-common/src/test/java/org/onap/aai/util/JettyObfuscationConversionCommandLineUtilTest.java
+++ b/vid-app-common/src/test/java/org/onap/aai/util/JettyObfuscationConversionCommandLineUtilTest.java
@@ -7,9 +7,9 @@
* 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.
@@ -20,23 +20,52 @@
package org.onap.aai.util;
+import static org.mockito.ArgumentMatchers.contains;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+
+import java.io.PrintStream;
+import java.util.Arrays;
import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
import org.onap.vid.aai.util.JettyObfuscationConversionCommandLineUtil;
+@RunWith(Parameterized.class)
public class JettyObfuscationConversionCommandLineUtilTest {
- private JettyObfuscationConversionCommandLineUtil createTestSubject() {
- return new JettyObfuscationConversionCommandLineUtil();
- }
+ final String[] args;
+ final String expected;
+
+ public JettyObfuscationConversionCommandLineUtilTest(String description, String[] args, String expected) {
+ this.args = args;
+ this.expected = expected;
+ }
-
- @Test
- public void testMain() throws Exception {
- String[] args = new String[] { "" };
+ @Parameters(name = "{0}")
+ public static Iterable<Object[]> data() {
+ return Arrays.asList(new Object[][]{
+ {"print usage on missing params", new String[]{}, "usage:"},
+ {"obfuscate", new String[]{"-e", "foobar"}, "OBF:1vub1ua51uh81ugi1u9d1vuz"},
+ {"deobfuscate", new String[]{"-d", "OBF:1vub1ua51uh81ugi1u9d1vuz"}, "foobar"},
+ {"input parse exception", new String[]{"mm", "-mm", "-mm"}, "failed to parse input"},
+ {"deobfuscate exception", new String[]{"-d", "problematic string"},
+ "exception:java.lang.NumberFormatException"},
+ });
+ }
- // default test
- JettyObfuscationConversionCommandLineUtil.main(args);
- }
+ @Test
+ public void testMain() {
+ final PrintStream originalOut = System.out;
+ try {
+ PrintStream mockedOut = mock(PrintStream.class);
+ System.setOut(mockedOut);
+ JettyObfuscationConversionCommandLineUtil.main(args);
+ verify(mockedOut).println(contains(expected));
+ } finally {
+ System.setOut(originalOut);
+ }
+ }
-
}
diff --git a/vid-app-common/src/test/java/org/onap/vid/aai/PombaClientImplTest.java b/vid-app-common/src/test/java/org/onap/vid/aai/PombaClientImplTest.java
index 222bf1e5b..c41a479d9 100644
--- a/vid-app-common/src/test/java/org/onap/vid/aai/PombaClientImplTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/aai/PombaClientImplTest.java
@@ -19,6 +19,7 @@
*/
package org.onap.vid.aai;
+import static org.assertj.core.api.Assertions.assertThatCode;
import static org.mockito.BDDMockito.given;
import static org.mockito.BDDMockito.then;
@@ -60,6 +61,20 @@ public class PombaClientImplTest {
then(pombaRestInterface).should().RestPost("VidAaiController", expectedUrl, expectedPayload);
}
+ @Test
+ public void should_handleException_withoutRethrowing() throws IOException {
+ //Given
+ String expectedUrl = "http://localhost/dummyUrl";
+ String expectedPayload = readExpectedPombaJsonRequest();
+ given(systemPropertiesWrapper.getProperty("pomba.server.url")).willReturn(expectedUrl);
+ given(pombaRestInterface.RestPost("VidAaiController", expectedUrl, expectedPayload))
+ .willThrow(new NullPointerException());
+ PombaRequest pombaRequest = createPombaRequest();
+
+ //When //Then
+ assertThatCode(() -> pombaClient.verify(pombaRequest)).doesNotThrowAnyException();
+ }
+
private String readExpectedPombaJsonRequest() throws IOException {
URL url = PombaClientImplTest.class.getClassLoader().getResource("pomba_request.json");
PombaRequest expectedPombaRequest = new ObjectMapper().readValue(url, PombaRequest.class);
diff --git a/vid-app-common/src/test/java/org/onap/vid/model/CategoryParameterOptionTest.java b/vid-app-common/src/test/java/org/onap/vid/model/CategoryParameterOptionTest.java
index 5fe392751..a3a14a2dd 100644
--- a/vid-app-common/src/test/java/org/onap/vid/model/CategoryParameterOptionTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/model/CategoryParameterOptionTest.java
@@ -20,190 +20,34 @@
package org.onap.vid.model;
-import java.io.Serializable;
-import java.util.Date;
-import java.util.Set;
+import static com.google.code.beanmatchers.BeanMatchers.hasValidBeanEqualsExcluding;
+import static com.google.code.beanmatchers.BeanMatchers.hasValidBeanHashCodeExcluding;
+import static com.google.code.beanmatchers.BeanMatchers.hasValidGettersAndSetters;
+import static org.hamcrest.MatcherAssert.assertThat;
-import org.junit.Assert;
+import org.apache.commons.lang3.ArrayUtils;
import org.junit.Test;
+import org.onap.portalsdk.core.domain.support.DomainVo;
+import org.onap.vid.testUtils.TestUtils;
public class CategoryParameterOptionTest {
- private CategoryParameterOption createTestSubject() {
- return new CategoryParameterOption();
- }
-
- @Test
- public void testGetId() throws Exception {
- CategoryParameterOption testSubject;
- Long result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getId();
- }
-
- @Test
- public void testSetId() throws Exception {
- CategoryParameterOption testSubject;
- Long id = null;
-
- // default test
- testSubject = createTestSubject();
- testSubject.setId(id);
- }
-
- @Test
- public void testGetAppId() throws Exception {
- CategoryParameterOption testSubject;
- String result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getAppId();
- }
-
- @Test
- public void testSetAppId() throws Exception {
- CategoryParameterOption testSubject;
- String appId = "";
-
- // default test
- testSubject = createTestSubject();
- testSubject.setAppId(appId);
- }
-
- @Test
- public void testGetName() throws Exception {
- CategoryParameterOption testSubject;
- String result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getName();
- }
-
- @Test
- public void testSetName() throws Exception {
- CategoryParameterOption testSubject;
- String name = "";
-
- // default test
- testSubject = createTestSubject();
- testSubject.setName(name);
- }
-
- @Test
- public void testGetCategoryParameter() throws Exception {
- CategoryParameterOption testSubject;
- CategoryParameter result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getCategoryParameter();
- }
-
- @Test
- public void testSetCategoryParameter() throws Exception {
- CategoryParameterOption testSubject;
- CategoryParameter categoryParameter = null;
-
- // default test
- testSubject = createTestSubject();
- testSubject.setCategoryParameter(categoryParameter);
- }
-
- @Test
- public void testGetCreated() throws Exception {
- CategoryParameterOption testSubject;
- Date result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getCreated();
- }
-
- @Test
- public void testGetModified() throws Exception {
- CategoryParameterOption testSubject;
- Date result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getModified();
- }
-
- @Test
- public void testGetCreatedId() throws Exception {
- CategoryParameterOption testSubject;
- Long result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getCreatedId();
- }
+ final private String[] excludedProperties = TestUtils.allPropertiesOf(DomainVo.class);
@Test
- public void testGetModifiedId() throws Exception {
- CategoryParameterOption testSubject;
- Long result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getModifiedId();
- }
-
- @Test
- public void testGetAuditUserId() throws Exception {
- CategoryParameterOption testSubject;
- Serializable result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getAuditUserId();
+ public void shouldHaveValidGettersAndSetters() {
+ assertThat(CategoryParameterOption.class, hasValidGettersAndSetters());
}
@Test
- public void testGetRowNum() throws Exception {
- CategoryParameterOption testSubject;
- Long result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getRowNum();
+ public void shouldHaveValidBeanHashCode() {
+ assertThat(CategoryParameterOption.class,
+ hasValidBeanHashCodeExcluding(ArrayUtils.addAll(new String[]{"categoryParameter"}, excludedProperties)));
}
@Test
- public void testGetAuditTrail() throws Exception {
- CategoryParameterOption testSubject;
- Set result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getAuditTrail();
- }
-
- @Test
- public void testEquals() throws Exception {
- CategoryParameterOption testSubject;
- Object o = null;
- boolean result;
-
- // test 1
- testSubject = createTestSubject();
- o = null;
- result = testSubject.equals(o);
- Assert.assertEquals(false, result);
- }
-
- @Test
- public void testHashCode() throws Exception {
- CategoryParameterOption testSubject;
- int result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.hashCode();
+ public void shouldHaveValidBeanEquals() {
+ assertThat(CategoryParameterOption.class, hasValidBeanEqualsExcluding(excludedProperties));
}
}
diff --git a/vid-app-common/src/test/java/org/onap/vid/model/CategoryParameterTest.java b/vid-app-common/src/test/java/org/onap/vid/model/CategoryParameterTest.java
index dc18c3065..c515a34d4 100644
--- a/vid-app-common/src/test/java/org/onap/vid/model/CategoryParameterTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/model/CategoryParameterTest.java
@@ -20,186 +20,64 @@
package org.onap.vid.model;
-import java.io.Serializable;
-import java.util.Date;
+import static com.google.code.beanmatchers.BeanMatchers.hasValidBeanEqualsExcluding;
+import static com.google.code.beanmatchers.BeanMatchers.hasValidBeanHashCodeExcluding;
+import static com.google.code.beanmatchers.BeanMatchers.hasValidGettersAndSettersExcluding;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.containsInAnyOrder;
+import static org.onap.vid.testUtils.TestUtils.allPropertiesOf;
+
+import com.google.common.collect.ImmutableSet;
import java.util.Set;
-
+import org.apache.commons.lang3.ArrayUtils;
import org.junit.Test;
+import org.onap.portalsdk.core.domain.support.DomainVo;
public class CategoryParameterTest {
- private CategoryParameter createTestSubject() {
- return new CategoryParameter();
- }
-
- @Test
- public void testGetFamily() throws Exception {
- CategoryParameter testSubject;
- String result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getFamily();
- }
-
- @Test
- public void testSetFamily() throws Exception {
- CategoryParameter testSubject;
- String family = "";
-
- // default test
- testSubject = createTestSubject();
- testSubject.setFamily(family);
- }
-
- @Test
- public void testGetId() throws Exception {
- CategoryParameter testSubject;
- Long result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getId();
- }
-
- @Test
- public void testGetCreated() throws Exception {
- CategoryParameter testSubject;
- Date result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getCreated();
- }
-
- @Test
- public void testGetModified() throws Exception {
- CategoryParameter testSubject;
- Date result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getModified();
- }
-
- @Test
- public void testGetCreatedId() throws Exception {
- CategoryParameter testSubject;
- Long result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getCreatedId();
- }
-
- @Test
- public void testGetModifiedId() throws Exception {
- CategoryParameter testSubject;
- Long result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getModifiedId();
- }
-
- @Test
- public void testGetName() throws Exception {
- CategoryParameter testSubject;
- String result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getName();
- }
- @Test
- public void testSetName() throws Exception {
- CategoryParameter testSubject;
- String name = "";
+ final private String[] excludedProperties = allPropertiesOf(DomainVo.class);
- // default test
- testSubject = createTestSubject();
- testSubject.setName(name);
+ private ImmutableSet<CategoryParameterOption> optionsWithRefTo(CategoryParameter categoryParameter) {
+ return ImmutableSet.of(
+ new CategoryParameterOption("appId1", "name1", categoryParameter),
+ new CategoryParameterOption("appId2", "name2", categoryParameter)
+ );
}
@Test
- public void testGetAuditUserId() throws Exception {
- CategoryParameter testSubject;
- Serializable result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getAuditUserId();
+ public void shouldHaveValidGettersAndSetters() {
+ assertThat(CategoryParameter.class, hasValidGettersAndSettersExcluding("options"));
}
@Test
- public void testGetRowNum() throws Exception {
- CategoryParameter testSubject;
- Long result;
+ public void testSetAndGetOptions() {
+ CategoryParameter testSubject = new CategoryParameter();
- // default test
- testSubject = createTestSubject();
- result = testSubject.getRowNum();
- }
-
- @Test
- public void testGetAuditTrail() throws Exception {
- CategoryParameter testSubject;
- Set result;
+ Set<CategoryParameterOption> options = optionsWithRefTo(testSubject);
- // default test
- testSubject = createTestSubject();
- result = testSubject.getAuditTrail();
+ testSubject.setOptions(options);
+ assertThat(testSubject.getOptions(), containsInAnyOrder(optionsWithRefTo(testSubject).toArray()));
}
@Test
- public void testGetOptions() throws Exception {
- CategoryParameter testSubject;
- Set<CategoryParameterOption> result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getOptions();
+ public void shouldHaveValidBeanHashCodeWithCycleReference() {
+ assertThat(CategoryParameter.class,
+ hasValidBeanHashCodeExcluding(ArrayUtils.addAll(new String[]{"options"}, excludedProperties)));
}
@Test
- public void testSetOptions() throws Exception {
- CategoryParameter testSubject;
- Set<CategoryParameterOption> options = null;
-
- // default test
- testSubject = createTestSubject();
+ public void hashCodeShouldNotExplodeWhenCycleReference() {
+ CategoryParameter testSubject = new CategoryParameter();
+ Set<CategoryParameterOption> options = optionsWithRefTo(testSubject);
testSubject.setOptions(options);
- }
- @Test
- public void testAddOption() throws Exception {
- CategoryParameter testSubject;
- CategoryParameterOption option = null;
- boolean result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.addOption(option);
+ testSubject.hashCode(); // don't stackOverflow
}
@Test
- public void testIsIdSupported() throws Exception {
- CategoryParameter testSubject;
- boolean result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.isIdSupported();
+ public void shouldHaveValidBeanEquals() {
+ assertThat(CategoryParameter.class, hasValidBeanEqualsExcluding(excludedProperties));
}
- @Test
- public void testSetIdSupported() throws Exception {
- CategoryParameter testSubject;
- boolean idSupported = false;
-
- // default test
- testSubject = createTestSubject();
- testSubject.setIdSupported(idSupported);
- }
}
diff --git a/vid-app-common/src/test/java/org/onap/vid/mso/MsoBusinessLogicImplTest.java b/vid-app-common/src/test/java/org/onap/vid/mso/MsoBusinessLogicImplTest.java
index a5fb1a5f0..39d777be9 100644
--- a/vid-app-common/src/test/java/org/onap/vid/mso/MsoBusinessLogicImplTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/mso/MsoBusinessLogicImplTest.java
@@ -3,14 +3,14 @@
* VID
* ================================================================================
* Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2018 - 2019 Nokia. All rights reserved.
+ * Modifications 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.
diff --git a/vid-app-common/src/test/java/org/onap/vid/mso/MsoResponseWrapper2Test.java b/vid-app-common/src/test/java/org/onap/vid/mso/MsoResponseWrapper2Test.java
index 5ec645a90..dd959a8aa 100644
--- a/vid-app-common/src/test/java/org/onap/vid/mso/MsoResponseWrapper2Test.java
+++ b/vid-app-common/src/test/java/org/onap/vid/mso/MsoResponseWrapper2Test.java
@@ -3,13 +3,14 @@
* VID
* ================================================================================
* Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved.
+ * Modifications 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.
@@ -20,41 +21,75 @@
package org.onap.vid.mso;
-import org.junit.Test;
+import static org.mockito.Mockito.when;
+
+import io.joshworks.restclient.http.HttpResponse;
+import org.mockito.Mock;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.MockitoAnnotations.initMocks;
public class MsoResponseWrapper2Test {
- private MsoResponseWrapper2 createTestSubject() {
- return new MsoResponseWrapper2(new RestObject());
+ @Mock
+ private RestObject<String> msoResponse;
+
+ @Mock
+ private HttpResponse<String> httpResponse;
+
+ private MsoResponseWrapper2<String> responseWrapper;
+
+ private int status = 202;
+ private String entity = "testEntity";
+ private String rawString = "testRawString";
+
+ @BeforeClass
+ public void setUp() {
+ initMocks(this);
}
@Test
- public void testGetStatus() throws Exception {
- MsoResponseWrapper2 testSubject;
- int result;
+ public void shouldProperlyCreateInstanceFromRestObject() {
+ // given
+ when(msoResponse.getStatusCode()).thenReturn(status);
+ when(msoResponse.get()).thenReturn(entity);
+ when(msoResponse.getRaw()).thenReturn(rawString);
+
+ // when
+ responseWrapper = new MsoResponseWrapper2<>(msoResponse);
- // default test
- testSubject = createTestSubject();
- result = testSubject.getStatus();
+ // then
+ assertThat(responseWrapper.getStatus()).isEqualTo(status);
+ assertThat(responseWrapper.getEntity()).isEqualTo(entity);
+ assertThat(responseWrapper.getResponse()).isEqualTo("{\"status\":"+status+",\"entity\":\""+entity+"\"}");
}
@Test
- public void testGetResponse() throws Exception {
- MsoResponseWrapper2 testSubject;
- String result;
+ public void shouldProperlyCreateInstanceFromHttpResponse() {
+ // given
+ when(httpResponse.getStatus()).thenReturn(status);
+ when(httpResponse.getBody()).thenReturn(entity);
- // default test
- testSubject = createTestSubject();
- result = testSubject.getResponse();
+ // when
+ responseWrapper = new MsoResponseWrapper2<>(httpResponse);
+
+ // then
+ assertThat(responseWrapper.getStatus()).isEqualTo(status);
+ assertThat(responseWrapper.getEntity()).isEqualTo(entity);
+ assertThat(responseWrapper.getResponse()).isEqualTo("{\"status\":"+status+",\"entity\":\""+entity+"\"}");
}
@Test
- public void testGetEntity() throws Exception {
- MsoResponseWrapper2 testSubject;
- Object result;
+ public void shouldProperlyCreateInstanceFromStatusAndEntity() {
+ // when
+ responseWrapper = new MsoResponseWrapper2<>(status,entity);
- // default test
- testSubject = createTestSubject();
- result = testSubject.getEntity();
+ // then
+ assertThat(responseWrapper.getStatus()).isEqualTo(status);
+ assertThat(responseWrapper.getEntity()).isEqualTo(entity);
+ assertThat(responseWrapper.getResponse()).isEqualTo("{\"status\":"+status+",\"entity\":\""+entity+"\"}");
}
-}
+
+} \ No newline at end of file
diff --git a/vid-app-common/src/test/java/org/onap/vid/mso/MsoResponseWrapperTest.java b/vid-app-common/src/test/java/org/onap/vid/mso/MsoResponseWrapperTest.java
index 6cba339d1..191b91ba2 100644
--- a/vid-app-common/src/test/java/org/onap/vid/mso/MsoResponseWrapperTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/mso/MsoResponseWrapperTest.java
@@ -25,12 +25,12 @@ import org.mockito.Mock;
import static com.google.code.beanmatchers.BeanMatchers.hasValidGettersAndSettersExcluding;
import static org.hamcrest.MatcherAssert.assertThat;
+import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
import static org.mockito.Mockito.when;
import static org.mockito.MockitoAnnotations.initMocks;
-import org.testng.annotations.BeforeSuite;
-import org.testng.annotations.Test;
-import static org.assertj.core.api.Assertions.assertThat;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
import javax.ws.rs.core.Response;
@@ -46,7 +46,7 @@ public class MsoResponseWrapperTest {
private MsoResponseWrapper responseWrapper;
- @BeforeSuite
+ @BeforeClass
public void setUp() {
initMocks(this);
}
@@ -57,45 +57,58 @@ public class MsoResponseWrapperTest {
}
@Test
- public void shouldProperlyConstructResponseWrapperWithParameters(){
+ public void shouldProperlyConstructMsoResponseWrapperWithParameters(){
+ // when
responseWrapper = new MsoResponseWrapper(1,"testEntity");
+ // then
assertThat(responseWrapper.getStatus()).isEqualTo(1);
assertThat(responseWrapper.getEntity()).isEqualTo("testEntity");
}
@Test
- public void shouldProperlyConstructResponseWrapperFromResponse(){
+ public void shouldProperlyConstructMsoResponseWrapperFromResponse(){
+ // given
when(response.getStatus()).thenReturn(1);
when(response.readEntity(String.class)).thenReturn("testEntity");
+ // when
responseWrapper = new MsoResponseWrapper(response);
+ // then
assertThat(responseWrapper.getStatus()).isEqualTo(1);
assertThat(responseWrapper.getEntity()).isEqualTo("testEntity");
}
@Test
public void shouldProperlyGetResponseWithEmptyEntity(){
+ // given
responseWrapper = new MsoResponseWrapper();
+
+ // when
responseWrapper.setStatus(1);
+ // then
assertThat(responseWrapper.getResponse()).isEqualToIgnoringWhitespace(PROPER_RESPONSE_WITH_NO_ENTITY);
}
@Test
public void shouldProperlyGetResponse(){
+ // when
responseWrapper = new MsoResponseWrapper(1,"testEntity");
+ // then
assertThat(responseWrapper.getResponse()).isEqualToIgnoringWhitespace(PROPER_RESPONSE);
}
@Test
public void shouldProperlyConvertToString(){
+ // when
responseWrapper = new MsoResponseWrapper(1,"testEntity");
+ // then
assertThat(responseWrapper.toString()).endsWith(PROPER_TO_STRING);
}
-}
+} \ No newline at end of file
diff --git a/vid-app-common/src/test/java/org/onap/vid/mso/RestObjectTest.java b/vid-app-common/src/test/java/org/onap/vid/mso/RestObjectTest.java
index 803083321..9f8614b92 100644
--- a/vid-app-common/src/test/java/org/onap/vid/mso/RestObjectTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/mso/RestObjectTest.java
@@ -7,9 +7,9 @@
* 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.
@@ -21,7 +21,7 @@
package org.onap.vid.mso;
import org.hamcrest.MatcherAssert;
-import org.testng.annotations.BeforeSuite;
+import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import static com.google.code.beanmatchers.BeanMatchers.hasValidGettersAndSettersExcluding;
@@ -29,11 +29,11 @@ import static org.assertj.core.api.Assertions.assertThat;
public class RestObjectTest {
- private RestObject restObject;
+ private RestObject<Object> restObject;
- @BeforeSuite
+ @BeforeClass
private void setUp() {
- restObject = new RestObject();
+ restObject = new RestObject<>();
}
@Test
@@ -42,7 +42,7 @@ public class RestObjectTest {
}
@Test
- public void shouldHaveValidGetterAndSetterForBody() {
+ public void shouldHaveValidGetterAndSetterForTObject() {
// given
String testString = "set/get_testString";
@@ -54,13 +54,13 @@ public class RestObjectTest {
}
@Test
- public void shouldProperlyCopyRestObject() {
+ public void shouldProperlyCopyFromOneRestObjectToAnotherWithProperParameters() {
// given
MsoResponseWrapper testResponseWraper = new MsoResponseWrapper();
String rawTestString = "rawTestString";
int statusCode = 404;
- RestObject restObjectToCopyFrom = new RestObject<>();
+ RestObject<Object> restObjectToCopyFrom = new RestObject<>();
restObjectToCopyFrom.set(testResponseWraper);
restObjectToCopyFrom.setRaw(rawTestString);
restObjectToCopyFrom.setStatusCode(statusCode);
@@ -91,4 +91,4 @@ public class RestObjectTest {
// then
assertThat(toStringResponse).isEqualTo(properString);
}
-}
+} \ No newline at end of file
diff --git a/vid-app-common/src/test/java/org/onap/vid/mso/model/OperationalEnvironmentActivateInfoTest.java b/vid-app-common/src/test/java/org/onap/vid/mso/model/OperationalEnvironmentActivateInfoTest.java
index 2a69e0e79..131e5dd46 100644
--- a/vid-app-common/src/test/java/org/onap/vid/mso/model/OperationalEnvironmentActivateInfoTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/mso/model/OperationalEnvironmentActivateInfoTest.java
@@ -7,9 +7,9 @@
* 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.
@@ -20,45 +20,48 @@
package org.onap.vid.mso.model;
-import org.junit.Test;
import org.onap.vid.controller.OperationalEnvironmentController;
-import org.onap.vid.controller.OperationalEnvironmentController.OperationalEnvironmentActivateBody;
import org.onap.vid.controller.OperationalEnvironmentController.OperationalEnvironmentManifest;
+import org.testng.annotations.Test;
-public class OperationalEnvironmentActivateInfoTest {
+import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
- private OperationalEnvironmentActivateInfo createTestSubject() {
- OperationalEnvironmentController.OperationalEnvironmentActivateBody a = new OperationalEnvironmentActivateBody("a", "b", "c", new OperationalEnvironmentManifest());
- return new OperationalEnvironmentActivateInfo(a, "", "");
- }
+public class OperationalEnvironmentActivateInfoTest {
@Test
- public void testGetUserId() throws Exception {
- OperationalEnvironmentActivateInfo testSubject;
- String result;
+ public void shouldProperlyCreateOperationalEnvironmentActivateInfoWithParameters() {
+ // given
+ String relatedInstanceId = "testRelatedInstanceId";
+ String relatedInstanceName = "testRelatedInstanceName";
+ String workloadContext = "testWorkloadContext";
+ OperationalEnvironmentManifest manifest = new OperationalEnvironmentManifest();
- // default test
- testSubject = createTestSubject();
- result = testSubject.getUserId();
- }
+ String userId = "testUserId";
+ String operationalEnvironmentId = "testOperationalEnvironmentId";
- @Test
- public void testGetOperationalEnvironmentId() throws Exception {
- OperationalEnvironmentActivateInfo testSubject;
- String result;
+ OperationalEnvironmentController.OperationalEnvironmentActivateBody operationalEnvironmentActivateBody =
+ new OperationalEnvironmentController.OperationalEnvironmentActivateBody
+ (relatedInstanceId,relatedInstanceName,workloadContext,manifest);
- // default test
- testSubject = createTestSubject();
- result = testSubject.getOperationalEnvironmentId();
- }
+ // when
+ OperationalEnvironmentActivateInfo operationalEnvironmentActivateInfo =
+ new OperationalEnvironmentActivateInfo(operationalEnvironmentActivateBody, userId, operationalEnvironmentId);
- @Test
- public void testToString() throws Exception {
- OperationalEnvironmentActivateInfo testSubject;
- String result;
- // default test
- testSubject = createTestSubject();
- result = testSubject.toString();
+ // then
+ assertThat(operationalEnvironmentActivateInfo.getUserId()).isEqualTo(userId);
+ assertThat(operationalEnvironmentActivateInfo.getOperationalEnvironmentId()).isEqualTo(operationalEnvironmentId);
+
+ assertThat(operationalEnvironmentActivateInfo.toString()).isEqualToIgnoringWhitespace(
+ "OperationalEnvironmentActivateInfo{operationalEnvironmentId="+operationalEnvironmentId+"," +
+ " userId="+userId+"," +
+ " super=OperationalEnvironmentActivateInfo{" +
+ " relatedInstanceId="+relatedInstanceId+"," +
+ " relatedInstanceName="+relatedInstanceName+"," +
+ " workloadContext="+workloadContext+"," +
+ " manifest="+manifest.toString()+"}}"
+ );
+
}
-}
+
+} \ No newline at end of file
diff --git a/vid-app-common/src/test/java/org/onap/vid/mso/model/OperationalEnvironmentDeactivateInfoTest.java b/vid-app-common/src/test/java/org/onap/vid/mso/model/OperationalEnvironmentDeactivateInfoTest.java
index 22310d2e2..72fb9d6dc 100644
--- a/vid-app-common/src/test/java/org/onap/vid/mso/model/OperationalEnvironmentDeactivateInfoTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/mso/model/OperationalEnvironmentDeactivateInfoTest.java
@@ -20,41 +20,31 @@
package org.onap.vid.mso.model;
-import org.junit.Test;
+import org.testng.annotations.Test;
+import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
public class OperationalEnvironmentDeactivateInfoTest {
- private OperationalEnvironmentDeactivateInfo createTestSubject() {
- return new OperationalEnvironmentDeactivateInfo("", "");
- }
-
@Test
- public void testGetUserId() throws Exception {
- OperationalEnvironmentDeactivateInfo testSubject;
- String result;
+ public void shouldProperlyCreateOperationalEnvironmentActivateInfoWithParameters() {
+ // given
+ String userId = "testUserId";
+ String operationalEnvironmentId = "testOperationalEnvironmentId";
- // default test
- testSubject = createTestSubject();
- result = testSubject.getUserId();
- }
- @Test
- public void testGetOperationalEnvironmentId() throws Exception {
- OperationalEnvironmentDeactivateInfo testSubject;
- String result;
+ // when
+ OperationalEnvironmentDeactivateInfo operationalEnvironmentDeactivateInfo =
+ new OperationalEnvironmentDeactivateInfo(userId, operationalEnvironmentId);
- // default test
- testSubject = createTestSubject();
- result = testSubject.getOperationalEnvironmentId();
- }
- @Test
- public void testToString() throws Exception {
- OperationalEnvironmentDeactivateInfo testSubject;
- String result;
+ // then
+ assertThat(operationalEnvironmentDeactivateInfo.getUserId()).isEqualTo(userId);
+ assertThat(operationalEnvironmentDeactivateInfo.getOperationalEnvironmentId()).isEqualTo(operationalEnvironmentId);
+
+ assertThat(operationalEnvironmentDeactivateInfo.toString()).isEqualToIgnoringWhitespace(
+ "OperationalEnvironmentDeactivateInfo{operationalEnvironmentId="+operationalEnvironmentId+"," +
+ " userId="+userId+"}"
+ );
- // default test
- testSubject = createTestSubject();
- result = testSubject.toString();
}
}
diff --git a/vid-app-common/src/test/java/org/onap/vid/services/ExtWorkflowServiceImplTest.java b/vid-app-common/src/test/java/org/onap/vid/services/ExternalWorkflowServiceImplTest.java
index d8d8552ec..160ba97a5 100644
--- a/vid-app-common/src/test/java/org/onap/vid/services/ExtWorkflowServiceImplTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/services/ExternalWorkflowServiceImplTest.java
@@ -38,13 +38,11 @@ import org.onap.vid.model.SOWorkflowType;
import org.onap.vid.model.SOWorkflows;
import org.onap.vid.mso.MsoResponseWrapper2;
import org.onap.vid.mso.rest.MockedWorkflowsRestClient;
-import org.onap.vid.services.ExtWorkflowsServiceImpl.BadResponseFromMso;
+import org.onap.vid.services.ExternalWorkflowsServiceImpl.BadResponseFromMso;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
-
-
-public class ExtWorkflowServiceImplTest {
+public class ExternalWorkflowServiceImplTest {
@Mock
private MockedWorkflowsRestClient client;
@@ -63,7 +61,7 @@ public class ExtWorkflowServiceImplTest {
@Test
public void shouldReturnWorkflowsOnValidResponse(){
// given
- ExtWorkflowsService extWorkflowsService = new ExtWorkflowsServiceImpl(client);
+ ExternalWorkflowsService extWorkflowsService = new ExternalWorkflowsServiceImpl(client);
Mockito.when(response.getStatus()).thenReturn(200);
Mockito.when(response.getBody()).thenReturn(new SOWorkflows(Collections.singletonList(new SOWorkflow(1L, "xyz"))));
MsoResponseWrapper2<SOWorkflows> msoResponseStub = new MsoResponseWrapper2<>(response);
@@ -78,7 +76,7 @@ public class ExtWorkflowServiceImplTest {
@Test(expectedExceptions = BadResponseFromMso.class)
public void shouldThrowBadResponseOnInvalidResponse(){
// given
- ExtWorkflowsService extWorkflowsService = new ExtWorkflowsServiceImpl(client);
+ ExternalWorkflowsService extWorkflowsService = new ExternalWorkflowsServiceImpl(client);
Mockito.when(response.getStatus()).thenReturn(500);
Mockito.when(response.getBody()).thenReturn(new SOWorkflows(Collections.singletonList(new SOWorkflow(1L, "xyz"))));
MsoResponseWrapper2<SOWorkflows> msoResponseStub = new MsoResponseWrapper2<>(response);
@@ -90,7 +88,7 @@ public class ExtWorkflowServiceImplTest {
@Test
public void shouldReturnWorkflowParametersOnValidResponse() {
SOWorkflowParameterDefinitions parameters = new SOWorkflowParameterDefinitions(Collections.singletonList(new SOWorkflowParameterDefinition(1L, "sample", "[0-9]", SOWorkflowType.STRING, true)));
- ExtWorkflowsService extWorkflowsService = new ExtWorkflowsServiceImpl(client);
+ ExternalWorkflowsService extWorkflowsService = new ExternalWorkflowsServiceImpl(client);
Mockito.when(parameterDefinitionsHttpResponse.getStatus()).thenReturn(200);
Mockito.when(parameterDefinitionsHttpResponse.getBody()).thenReturn(parameters);
MsoResponseWrapper2<SOWorkflowParameterDefinitions> msoResponseWrapper = new MsoResponseWrapper2<>(parameterDefinitionsHttpResponse);
@@ -104,7 +102,7 @@ public class ExtWorkflowServiceImplTest {
@Test
public void shouldProperlyHandleEmptyParametersList(){
- ExtWorkflowsService extWorkflowsService = new ExtWorkflowsServiceImpl(client);
+ ExternalWorkflowsService extWorkflowsService = new ExternalWorkflowsServiceImpl(client);
Mockito.when(parameterDefinitionsHttpResponse.getStatus()).thenReturn(200);
Mockito.when(parameterDefinitionsHttpResponse.getBody()).thenReturn(new SOWorkflowParameterDefinitions(Lists.newArrayList()));
diff --git a/vid-app-common/src/test/java/org/onap/vid/services/JobsBrokerServiceTest.java b/vid-app-common/src/test/java/org/onap/vid/services/JobsBrokerServiceTest.java
index 7b51225f3..85cf23edd 100644
--- a/vid-app-common/src/test/java/org/onap/vid/services/JobsBrokerServiceTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/services/JobsBrokerServiceTest.java
@@ -21,8 +21,45 @@
package org.onap.vid.services;
+import static java.util.concurrent.TimeUnit.MILLISECONDS;
+import static java.util.stream.Collectors.toList;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.both;
+import static org.hamcrest.Matchers.containsInAnyOrder;
+import static org.onap.vid.job.Job.JobStatus.COMPLETED;
+import static org.onap.vid.job.Job.JobStatus.CREATING;
+import static org.onap.vid.job.Job.JobStatus.FAILED;
+import static org.onap.vid.job.Job.JobStatus.IN_PROGRESS;
+import static org.onap.vid.job.Job.JobStatus.PAUSE;
+import static org.onap.vid.job.Job.JobStatus.PENDING;
+import static org.onap.vid.job.Job.JobStatus.RESOURCE_IN_PROGRESS;
+import static org.onap.vid.job.Job.JobStatus.STOPPED;
+import static org.onap.vid.utils.Streams.not;
+import static org.testng.Assert.assertNotNull;
+import static org.testng.AssertJUnit.assertEquals;
+
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
+import java.lang.reflect.Method;
+import java.time.LocalDateTime;
+import java.time.ZoneId;
+import java.util.Arrays;
+import java.util.Date;
+import java.util.List;
+import java.util.Optional;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.ConcurrentSkipListSet;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeoutException;
+import java.util.stream.IntStream;
+import java.util.stream.Stream;
+import javax.inject.Inject;
import org.apache.commons.lang.RandomStringUtils;
import org.apache.commons.lang3.RandomUtils;
import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
@@ -53,27 +90,6 @@ import org.testng.annotations.BeforeMethod;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
-import javax.inject.Inject;
-import java.lang.reflect.Method;
-import java.time.LocalDateTime;
-import java.time.ZoneId;
-import java.util.*;
-import java.util.concurrent.*;
-import java.util.stream.IntStream;
-import java.util.stream.Stream;
-
-import static java.util.concurrent.TimeUnit.MILLISECONDS;
-import static java.util.stream.Collectors.toList;
-import static org.hamcrest.CoreMatchers.equalTo;
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.both;
-import static org.hamcrest.Matchers.containsInAnyOrder;
-import static org.onap.vid.job.Job.JobStatus.*;
-import static org.onap.vid.utils.Streams.not;
-import static org.testng.Assert.assertNotNull;
-import static org.testng.AssertJUnit.assertEquals;
-
@ContextConfiguration(classes = {DataSourceConfig.class, SystemProperties.class, JobAdapterConfig.class})
public class JobsBrokerServiceTest extends AbstractTestNGSpringContextTests {
@@ -85,7 +101,7 @@ public class JobsBrokerServiceTest extends AbstractTestNGSpringContextTests {
private final Set<Long> threadsIds = new ConcurrentSkipListSet<>();
- private final long FEW = 500;
+ private final long FEW = 1000;
private final String JOBS_SHOULD_MATCH = "the jobs that added and those that pulled must be the same";
private final String JOBS_PEEKED_SHOULD_MATCH = "the jobs that added and those that peeked must be the same";
diff --git a/vid-app-common/src/test/java/org/onap/vid/testUtils/TestUtils.java b/vid-app-common/src/test/java/org/onap/vid/testUtils/TestUtils.java
index e2effd5ca..3a7d4690d 100644
--- a/vid-app-common/src/test/java/org/onap/vid/testUtils/TestUtils.java
+++ b/vid-app-common/src/test/java/org/onap/vid/testUtils/TestUtils.java
@@ -20,9 +20,32 @@
package org.onap.vid.testUtils;
+import static org.apache.commons.beanutils.PropertyUtils.getPropertyDescriptors;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.RETURNS_DEFAULTS;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+import static org.mockito.Mockito.withSettings;
+import static org.testng.Assert.fail;
+
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.ImmutableList;
+import java.beans.PropertyDescriptor;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Serializable;
+import java.net.URI;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
+import javax.ws.rs.client.Client;
+import javax.ws.rs.client.Invocation;
+import javax.ws.rs.client.WebTarget;
+import javax.ws.rs.core.GenericType;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.json.JSONArray;
@@ -32,28 +55,11 @@ import org.mockito.MockSettings;
import org.mockito.Mockito;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
+import org.onap.portalsdk.core.domain.support.DomainVo;
import org.onap.portalsdk.core.util.SystemProperties;
import org.onap.vid.asdc.beans.Service;
import org.springframework.mock.env.MockEnvironment;
-import javax.ws.rs.client.Client;
-import javax.ws.rs.client.Invocation;
-import javax.ws.rs.client.WebTarget;
-import javax.ws.rs.core.GenericType;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.Serializable;
-import java.net.URI;
-import java.util.Iterator;
-import java.util.List;
-
-import static fj.parser.Parser.fail;
-import static org.mockito.Matchers.any;
-import static org.mockito.Mockito.*;
-
/**
* Created by Oren on 6/7/17.
*/
@@ -125,6 +131,12 @@ public class TestUtils {
valueType);
}
+ public static String[] allPropertiesOf(Class<DomainVo> aClass) {
+ return Arrays.stream(getPropertyDescriptors(aClass))
+ .map(PropertyDescriptor::getDisplayName)
+ .toArray(String[]::new);
+ }
+
public static class JavaxRsClientMocks {
private final javax.ws.rs.client.Client fakeClient;