aboutsummaryrefslogtreecommitdiffstats
path: root/cmso-service/src/test/java
diff options
context:
space:
mode:
Diffstat (limited to 'cmso-service/src/test/java')
-rw-r--r--cmso-service/src/test/java/org/onap/optf/cmso/JpaInit.java57
-rw-r--r--cmso-service/src/test/java/org/onap/optf/cmso/JtestHelper.java61
-rw-r--r--cmso-service/src/test/java/org/onap/optf/cmso/service/H2Test.java47
-rw-r--r--cmso-service/src/test/java/org/onap/optf/cmso/service/rs/CMSOServiceImplTest.java158
-rw-r--r--cmso-service/src/test/java/org/onap/optf/cmso/service/rs/MockHttpServletRequest.java49
-rw-r--r--cmso-service/src/test/java/org/onap/optf/cmso/utilities/PropertiesAdmin.java52
6 files changed, 424 insertions, 0 deletions
diff --git a/cmso-service/src/test/java/org/onap/optf/cmso/JpaInit.java b/cmso-service/src/test/java/org/onap/optf/cmso/JpaInit.java
new file mode 100644
index 0000000..8a3aa58
--- /dev/null
+++ b/cmso-service/src/test/java/org/onap/optf/cmso/JpaInit.java
@@ -0,0 +1,57 @@
+/*
+ * Copyright © 2017-2018 AT&T Intellectual Property.
+ * Modifications Copyright © 2018 IBM.
+ *
+ * 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.
+ *
+ *
+ * Unless otherwise specified, all documentation contained herein is licensed
+ * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
+ * you may not use this documentation except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://creativecommons.org/licenses/by/4.0/
+ *
+ * Unless required by applicable law or agreed to in writing, documentation
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+
+package org.onap.optf.cmso;
+
+import java.util.concurrent.atomic.AtomicBoolean;
+import org.onap.optf.cmso.model.ApprovalType;
+import org.onap.optf.cmso.model.Domain;
+import org.springframework.boot.test.autoconfigure.orm.jpa.TestEntityManager;
+
+public class JpaInit {
+
+ private static AtomicBoolean initialized = new AtomicBoolean(false);
+
+ public static void init(TestEntityManager entityManager) {
+ if (initialized.compareAndSet(true, true))
+ return;
+ Domain d = new Domain();
+ d.setDomain("ChangeManagement");
+ entityManager.persist(d);
+ ApprovalType at = new ApprovalType();
+ at.setApprovalCount(1);
+ at.setDomain("ChangeManagement");
+ at.setApprovalType("Tier 2");
+ entityManager.persist(at);
+ entityManager.flush();
+
+ }
+}
diff --git a/cmso-service/src/test/java/org/onap/optf/cmso/JtestHelper.java b/cmso-service/src/test/java/org/onap/optf/cmso/JtestHelper.java
new file mode 100644
index 0000000..d0b03e5
--- /dev/null
+++ b/cmso-service/src/test/java/org/onap/optf/cmso/JtestHelper.java
@@ -0,0 +1,61 @@
+/*
+ * Copyright © 2017-2018 AT&T Intellectual Property.
+ * Modifications Copyright © 2018 IBM.
+ *
+ * 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.
+ *
+ *
+ * Unless otherwise specified, all documentation contained herein is licensed
+ * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
+ * you may not use this documentation except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://creativecommons.org/licenses/by/4.0/
+ *
+ * Unless required by applicable law or agreed to in writing, documentation
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+
+package org.onap.optf.cmso;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.util.Map;
+import java.util.Scanner;
+import org.apache.commons.lang3.text.StrSubstitutor;
+
+public class JtestHelper {
+ private static String templatefolder = "src/test/templates" + File.separator;
+
+ public static String template(String filename, Map<String, String> values) {
+ String data = "";
+ Scanner s = null;
+ try {
+ File t = new File(templatefolder + filename);
+ s = new Scanner(t);
+ s.useDelimiter("\\Z");
+ data = s.next();
+ StrSubstitutor ss = new StrSubstitutor(values);
+ data = ss.replace(data);
+ } catch (FileNotFoundException e) {
+ data = "";
+ } finally {
+ if (s != null)
+ s.close();
+ }
+ return data;
+ }
+}
diff --git a/cmso-service/src/test/java/org/onap/optf/cmso/service/H2Test.java b/cmso-service/src/test/java/org/onap/optf/cmso/service/H2Test.java
new file mode 100644
index 0000000..8a586a9
--- /dev/null
+++ b/cmso-service/src/test/java/org/onap/optf/cmso/service/H2Test.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright © 2017-2018 AT&T Intellectual Property.
+ * Modifications Copyright © 2018 IBM.
+ *
+ * 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.
+ *
+ *
+ * Unless otherwise specified, all documentation contained herein is licensed
+ * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
+ * you may not use this documentation except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://creativecommons.org/licenses/by/4.0/
+ *
+ * Unless required by applicable law or agreed to in writing, documentation
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+
+package org.onap.optf.cmso.service;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration(locations = {"classpath:testConfig.xml"})
+public class H2Test {
+
+ @Test
+ public void h2Test() {
+
+ }
+}
diff --git a/cmso-service/src/test/java/org/onap/optf/cmso/service/rs/CMSOServiceImplTest.java b/cmso-service/src/test/java/org/onap/optf/cmso/service/rs/CMSOServiceImplTest.java
new file mode 100644
index 0000000..c8039ad
--- /dev/null
+++ b/cmso-service/src/test/java/org/onap/optf/cmso/service/rs/CMSOServiceImplTest.java
@@ -0,0 +1,158 @@
+/*
+ * Copyright © 2017-2018 AT&T Intellectual Property.
+ * Modifications Copyright © 2018 IBM.
+ *
+ * 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.
+ *
+ *
+ * Unless otherwise specified, all documentation contained herein is licensed
+ * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
+ * you may not use this documentation except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://creativecommons.org/licenses/by/4.0/
+ *
+ * Unless required by applicable law or agreed to in writing, documentation
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+
+package org.onap.optf.cmso.service.rs;
+
+import static org.junit.Assert.assertEquals;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.UUID;
+import javax.ws.rs.core.Response;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.onap.optf.cmso.JpaInit;
+import org.onap.optf.cmso.JtestHelper;
+import org.onap.optf.cmso.common.CMSRequestError;
+import org.onap.optf.cmso.service.rs.models.CMSMessage;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
+import org.springframework.boot.test.autoconfigure.orm.jpa.TestEntityManager;
+import org.springframework.test.context.junit4.SpringRunner;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import scala.collection.mutable.StringBuilder;
+
+@RunWith(SpringRunner.class)
+@DataJpaTest
+public class CMSOServiceImplTest {
+
+ @Autowired
+ CMSOServiceImpl cMSOServiceImpl;
+
+ @Autowired
+ private TestEntityManager entityManager;
+
+ @Before
+ public void setUp() throws Exception {
+ JpaInit.init(entityManager);
+ }
+
+ @Test
+ public void test_createScheduleRequest() {
+ String[] templates = {"changemanagement/MultipleVnfImmediate.json.template",};
+ String[] domains = {"ChangeManagement",};
+ String[] userIds = {"jf9860",};
+ String[] callbackUrls = {"http://localhost:8089/",};
+ String[] callbackDatum = {"sdafafadfdasfdsafdsa",};
+ String[] workflows = {"Replace", "Update", "NewOne",};
+ Integer[] normalDurationInSeeconds = {10,};
+ Integer[] additionalDurationInSeeconds = {10,};
+ String[] results = {"500:", // {additionalDurationInSeconds=10, workflow=Replace,
+ // domain=ChangeManagement,
+ // callbackData=sdafafadfdasfdsafdsa, testid=79e1,
+ // callbackUrl=http://localhost:8089/,
+ // uuid=a36b45b9-dff4-45b4-ac6b-2a4f35e179e1, userId=jf9860,
+ // normalDurationInSeconds=10}
+ "500:", // {additionalDurationInSeconds=10, workflow=Update,
+ // domain=ChangeManagement,
+ // callbackData=sdafafadfdasfdsafdsa, testid=c525,
+ // callbackUrl=http://localhost:8089/,
+ // uuid=26b189f7-b075-4013-b487-d938b895c525, userId=jf9860,
+ // normalDurationInSeconds=10}
+ "500:", // {additionalDurationInSeconds=10, workflow=NewOne,
+ // domain=ChangeManagement,
+ // callbackData=sdafafadfdasfdsafdsa, testid=8e87,
+ // callbackUrl=http://localhost:8089/,
+ // uuid=4f59b14a-8040-4257-8981-defcb8f38e87, userId=jf9860,
+ // normalDurationInSeconds=10}
+ };
+
+ int i = 0;
+ for (String template : templates) {
+ for (String domain : domains) {
+ for (String userId : userIds) {
+ for (String callbackUrl : callbackUrls) {
+ for (String callbackData : callbackDatum) {
+ for (String workflow : workflows) {
+ for (Integer normalDuration : normalDurationInSeeconds) {
+ for (Integer additionalDuration : additionalDurationInSeeconds) {
+ Map<String, String> values = new HashMap<String, String>();
+ String scheduleId = UUID.randomUUID().toString();
+ values.put("uuid", scheduleId);
+ values.put("testid", scheduleId.substring(scheduleId.length() - 4));
+ values.put("domain", domain);
+ values.put("userId", userId);
+ values.put("callbackUrl", callbackUrl);
+ values.put("callbackData", callbackData);
+ values.put("workflow", workflow);
+ values.put("normalDurationInSeconds", normalDuration.toString());
+ values.put("additionalDurationInSeconds", additionalDuration.toString());
+ String json = JtestHelper.template(template, values);
+ ObjectMapper om = new ObjectMapper();
+ CMSMessage scheduleMessage;
+ try {
+ scheduleMessage = om.readValue(json, CMSMessage.class);
+ MockHttpServletRequest mrequest = new MockHttpServletRequest();
+ mrequest.url.append(scheduleId);
+
+ Response response = cMSOServiceImpl.createScheduleRequest("v2", scheduleId,
+ scheduleMessage, mrequest.request);
+
+ Object result = response.getEntity();
+ StringBuilder sb = new StringBuilder();
+ sb.append(response.getStatus()).append(":");
+ if (result instanceof CMSRequestError) {
+ String r = result.toString().replaceAll(" : Reason :.*$", "");
+ sb.append(r.replaceAll(scheduleId, "<uuid>"));
+ }
+ // Generate results[] entry
+ System.out.println("\"" + sb.toString() + "\", //" + values.toString());
+
+ // Debug an assertion
+ System.out.println(results[i] + ":" + sb.toString());
+ assertEquals(results[i].equals(sb.toString()), true);
+ i++;
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ }
+ }
+ }
+
+ }
+ }
+ }
+ }
+ }
+ }
+}
diff --git a/cmso-service/src/test/java/org/onap/optf/cmso/service/rs/MockHttpServletRequest.java b/cmso-service/src/test/java/org/onap/optf/cmso/service/rs/MockHttpServletRequest.java
new file mode 100644
index 0000000..aace25e
--- /dev/null
+++ b/cmso-service/src/test/java/org/onap/optf/cmso/service/rs/MockHttpServletRequest.java
@@ -0,0 +1,49 @@
+/*
+ * Copyright © 2017-2018 AT&T Intellectual Property.
+ * Modifications Copyright © 2018 IBM.
+ *
+ * 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.
+ *
+ *
+ * Unless otherwise specified, all documentation contained herein is licensed
+ * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
+ * you may not use this documentation except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://creativecommons.org/licenses/by/4.0/
+ *
+ * Unless required by applicable law or agreed to in writing, documentation
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+
+package org.onap.optf.cmso.service.rs;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+import javax.servlet.http.HttpServletRequest;
+
+public class MockHttpServletRequest {
+ public StringBuffer url = new StringBuffer("http://localhost:8089/cmso/v1/ChangeManagement/schedules/");
+ public HttpServletRequest request = mock(HttpServletRequest.class);
+
+ MockHttpServletRequest() {
+
+ when(request.getRequestURL()).thenReturn(url);
+ when(request.getHeader("Authorization")).thenReturn("BasicbTEzODc3OnNjaGVkdWxlci1SMTgwMiE=");
+
+ }
+
+}
diff --git a/cmso-service/src/test/java/org/onap/optf/cmso/utilities/PropertiesAdmin.java b/cmso-service/src/test/java/org/onap/optf/cmso/utilities/PropertiesAdmin.java
new file mode 100644
index 0000000..faf408b
--- /dev/null
+++ b/cmso-service/src/test/java/org/onap/optf/cmso/utilities/PropertiesAdmin.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright © 2017-2018 AT&T Intellectual Property.
+ * Modifications Copyright © 2018 IBM.
+ *
+ * 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.
+ *
+ *
+ * Unless otherwise specified, all documentation contained herein is licensed
+ * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
+ * you may not use this documentation except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://creativecommons.org/licenses/by/4.0/
+ *
+ * Unless required by applicable law or agreed to in writing, documentation
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+
+package org.onap.optf.cmso.utilities;
+
+import org.onap.optf.cmso.common.PropertiesManagement;
+
+public class PropertiesAdmin {
+ public static void main(String[] args) {
+ PropertiesManagement pm = new PropertiesManagement();
+ if (args.length < 1) {
+ System.out.println("Missing argument");
+ return;
+ }
+ String value = "";
+ if (args[0].startsWith("dec:")) {
+ value = PropertiesManagement.getDecryptedValue(args[0].substring(4));
+ } else {
+ value = pm.getEncryptedValue(args[0]);
+ }
+ System.out.println(args[0] + " : " + value);
+ }
+
+}