diff options
author | Arthur Martella <arthur.martella.1@att.com> | 2019-03-15 12:25:44 -0400 |
---|---|---|
committer | Arthur Martella <arthur.martella.1@att.com> | 2019-03-15 12:25:44 -0400 |
commit | 45d1330477382bed46418936e89c0ce0e6f9dcc8 (patch) | |
tree | c343bef8ccd272a552b344d2750c05ab43b00e6c /valetapi/src | |
parent | 271147710dcf111f802503b6b34ff5cb9a3eb2cf (diff) |
Initial upload of F-GPS seed code 11/21
Includes:
API test code and resources
Change-Id: Ib5675b9e9102ac8b86b2c4f9cc518840cebdbc8d
Issue-ID: OPTFRA-440
Signed-off-by: arthur.martella.1@att.com
Diffstat (limited to 'valetapi/src')
7 files changed, 945 insertions, 0 deletions
diff --git a/valetapi/src/test/java/org/onap/fgps/api/componenttest/mockito/ITComponentTest.java b/valetapi/src/test/java/org/onap/fgps/api/componenttest/mockito/ITComponentTest.java new file mode 100644 index 0000000..c6eee45 --- /dev/null +++ b/valetapi/src/test/java/org/onap/fgps/api/componenttest/mockito/ITComponentTest.java @@ -0,0 +1,54 @@ +/* + * ============LICENSE_START========================================== + * ONAP - F-GPS API + * =================================================================== + * Copyright © 2019 ATT Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the "License"); + * you may not use this software 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. + * + * ============LICENSE_END============================================ + * + * + */ +package org.onap.fgps.api.componenttest.mockito;
+
+import static org.junit.Assert.*;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import org.junit.Test;
+
+public class ITComponentTest {
+
+ @Test
+ public void greets() {
+ String msg = "Hello User!";
+ assertEquals(msg, "Hello User!");
+ }
+
+}
\ No newline at end of file diff --git a/valetapi/src/test/java/org/onap/fgps/controller/ValetGroupsControllerTest.java b/valetapi/src/test/java/org/onap/fgps/controller/ValetGroupsControllerTest.java new file mode 100644 index 0000000..3f92566 --- /dev/null +++ b/valetapi/src/test/java/org/onap/fgps/controller/ValetGroupsControllerTest.java @@ -0,0 +1,107 @@ +/* + * ============LICENSE_START========================================== + * ONAP - F-GPS API + * =================================================================== + * Copyright - 2019 ATT Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the "License"); + * you may not use this software 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. + * + * ============LICENSE_END============================================ + * + * + */ +package org.onap.fgps.controller;
+/*package com.valet.controller;
+
+import static org.assertj.core.api.Assertions.fail;
+import static org.junit.Assert.assertEquals;
+
+import java.io.BufferedReader;
+import java.io.FileInputStream;
+import java.io.InputStreamReader;
+
+import javax.ws.rs.client.Entity;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import org.jboss.resteasy.client.jaxrs.ResteasyClient;
+import org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder;
+import org.jboss.resteasy.client.jaxrs.ResteasyWebTarget;
+import org.json.simple.JSONObject;
+import org.json.simple.parser.JSONParser;
+import org.junit.Test;
+import org.skyscreamer.jsonassert.JSONAssert;
+
+
+public class ValetGroupsControllerTest {
+
+
+ @Test
+ public void testPotal1() throws Exception {
+ String expectedOutput = "{}";
+ // Do a REST call
+ ResteasyClient client = new ResteasyClientBuilder().build();
+ ResteasyWebTarget target = client.target("http://localhost:8080/api/valet/groups/v1/portal?requestId=12345");
+ Response response = target.request().get();
+ String respnseData = response.readEntity(String.class);
+ response.close();
+ JSONObject responseDataJSON = (JSONObject)new JSONParser().parse(respnseData);
+ respnseData = ((JSONObject)responseDataJSON.get("values")).get("request").toString();
+ System.out.println("Expected :");
+ System.out.println(expectedOutput);
+ System.out.println("Actual :");
+ System.out.println(respnseData);
+ // Compare the outputs
+ assertEquals(expectedOutput, respnseData);
+ }
+ @Test
+ public void testPortal2() throws Exception {
+ try(BufferedReader brOutput = new BufferedReader(new InputStreamReader(new FileInputStream("\\testing\\portal\\Advancedsearch\\advancedsearchoutput.txt")))) {
+ String expectedOutput = brOutput.readLine();
+ JSONObject expectedOuptutJSON = (JSONObject)new JSONParser().parse(expectedOutput);
+ // Do a REST call
+ ResteasyClient client = new ResteasyClientBuilder().build();
+ ResteasyWebTarget target = client.target("http://localhost:8080/api/valet/groups/v1/portal?requestId=12345&name=VALET_HOST_DIVERSITY_RULE&datacenter_id=mtn6");
+ Response response = target.request().get();
+ String respnseData = response.readEntity(String.class);
+ response.close();
+ expectedOutput = ((JSONObject)((JSONObject)expectedOuptutJSON.get("values")).get("request")).toJSONString();
+ JSONObject responseDataJSON = (JSONObject)new JSONParser().parse(respnseData);
+ respnseData = ((JSONObject)responseDataJSON.get("values")).get("request").toString();
+ System.out.println("Expected :");
+ System.out.println(expectedOutput);
+ System.out.println("Actual :");
+ System.out.println(respnseData);
+ // Compare the outputs
+ assertEquals(expectedOutput, respnseData);
+ }catch(Exception e) {
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+ }
+}*/
\ No newline at end of file diff --git a/valetapi/src/test/java/org/onap/fgps/controller/ValetServicePlacementControllerTest.java b/valetapi/src/test/java/org/onap/fgps/controller/ValetServicePlacementControllerTest.java new file mode 100644 index 0000000..7762283 --- /dev/null +++ b/valetapi/src/test/java/org/onap/fgps/controller/ValetServicePlacementControllerTest.java @@ -0,0 +1,221 @@ +/* + * ============LICENSE_START========================================== + * ONAP - F-GPS API + * =================================================================== + * Copyright - 2019 ATT Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the "License"); + * you may not use this software 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. + * + * ============LICENSE_END============================================ + * + * + */ +package org.onap.fgps.controller;
+/*package com.valet.controller;
+
+import static org.assertj.core.api.Assertions.fail;
+import static org.junit.Assert.assertEquals;
+
+import java.io.BufferedReader;
+import java.io.FileInputStream;
+import java.io.InputStreamReader;
+
+import javax.ws.rs.client.Entity;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import org.jboss.resteasy.client.jaxrs.ResteasyClient;
+import org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder;
+import org.jboss.resteasy.client.jaxrs.ResteasyWebTarget;
+import org.json.simple.JSONObject;
+import org.json.simple.parser.JSONParser;
+import org.junit.Test;
+import org.skyscreamer.jsonassert.JSONAssert;
+
+
+public class ValetServicePlacementControllerTest {
+
+ @Test
+ public void testCreateVM2() throws Exception {
+ try(BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream("\\testing\\createoperationandupdate\\diversitynested\\create_req_ValetHostDiversityNest_20180509e.txt")))) {
+ try(BufferedReader brOutput = new BufferedReader(new InputStreamReader(new FileInputStream("\\testing\\createoperationandupdate\\diversitynested\\diversitynestedoutput.txt")))) {
+ JSONObject input = (JSONObject)new JSONParser().parse(br);
+ String expectedOutput = brOutput.readLine();
+ JSONObject expectedOuptutJSON = (JSONObject)new JSONParser().parse(expectedOutput);
+ // Do a REST call
+ ResteasyClient client = new ResteasyClientBuilder().build();
+ ResteasyWebTarget target = client.target("http://localhost:8080/api/valet/placement/v1/createVM2?requestId=create-123");
+ Response response = target.request().post(Entity.entity(input.toJSONString(), MediaType.APPLICATION_JSON));
+ String respnseData = response.readEntity(String.class);
+ response.close();
+ expectedOutput = ((JSONObject)((JSONObject)expectedOuptutJSON.get("values")).get("request")).toJSONString();
+ System.out.println("Expected :");
+ System.out.println(expectedOutput);
+ System.out.println("Actual :");
+ System.out.println(respnseData);
+ // Compare the outputs
+ JSONAssert.assertEquals(expectedOutput, respnseData, false);
+ }
+ }catch(Exception e) {
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+ }
+ @Test
+ public void testupdateVm1() throws Exception {
+ try(BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream("\\\\testing\\\\createoperationandupdate\\\\diversitynested\\\\create_req_ValetHostDiversityNest_20180509e.txt")))) {
+ try(BufferedReader brOutput = new BufferedReader(new InputStreamReader(new FileInputStream("\\\\testing\\\\createoperationandupdate\\\\diversitynested\\\\diversitynestedoutput.txt")))) {
+ JSONObject input = (JSONObject)new JSONParser().parse(br);
+ String expectedOutput = brOutput.readLine();
+ JSONObject expectedOuptutJSON = (JSONObject)new JSONParser().parse(expectedOutput);
+ // Do a REST call
+ ResteasyClient client = new ResteasyClientBuilder().build();
+ ResteasyWebTarget target = client.target("http://localhost:8080/api/valet/placement/v1/updateVm1?requestId=update-123");
+ Response response = target.request().put(Entity.entity(input.toJSONString(), MediaType.APPLICATION_JSON));
+ String respnseData = response.readEntity(String.class);
+ response.close();
+ expectedOutput = ((JSONObject)((JSONObject)expectedOuptutJSON.get("values")).get("request")).toJSONString();
+ System.out.println("Expected :");
+ System.out.println(expectedOutput);
+ System.out.println("Actual :");
+ System.out.println(respnseData);
+ // Compare the outputs
+ JSONAssert.assertEquals(expectedOutput, respnseData, false);
+ }
+ }catch(Exception e) {
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+ }
+ @Test
+ public void testdeleteVm1() throws Exception {
+ try(BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream("\\testing\\Deleteoperation\\deleteinput.txt")))) {
+ try(BufferedReader brOutput = new BufferedReader(new InputStreamReader(new FileInputStream("\\\\testing\\\\Deleteoperation\\\\deleteoutput.txt")))) {
+ JSONObject input = (JSONObject)new JSONParser().parse(br);
+ String expectedOutput = brOutput.readLine();
+ JSONObject expectedOuptutJSON = (JSONObject)new JSONParser().parse(expectedOutput);
+ // Do a REST call
+ ResteasyClient client = new ResteasyClientBuilder().build();
+ ResteasyWebTarget target = client.target("http://localhost:8080/api/valet/placement/v1/deleteVm1?requestId=delete-123");
+ Response response = target.request().build("DELETE", Entity.entity(input.toJSONString(), MediaType.APPLICATION_JSON)).invoke();
+ String respnseData = response.readEntity(String.class);
+ response.close();
+ expectedOutput = ((JSONObject)((JSONObject)expectedOuptutJSON.get("values")).get("request")).toJSONString();
+ JSONObject responseDataJSON = (JSONObject)new JSONParser().parse(respnseData);
+ respnseData = ((JSONObject)responseDataJSON.get("values")).get("request").toString();
+ System.out.println("Expected :");
+ System.out.println(expectedOutput);
+ System.out.println("Actual :");
+ System.out.println(respnseData);
+ // Compare the outputs
+ JSONAssert.assertEquals(expectedOutput, respnseData, false);
+ }
+ }catch(Exception e) {
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+ }
+ @Test
+ public void testconfirm1() throws Exception {
+ try(BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream("\\testing\\Confirm\\confriminput.txt")))) {
+ try(BufferedReader brOutput = new BufferedReader(new InputStreamReader(new FileInputStream("\\testing\\Confirm\\confrimoutput.txt")))) {
+ JSONObject input = (JSONObject)new JSONParser().parse(br);
+ String expectedOutput = brOutput.readLine();
+ JSONObject expectedOuptutJSON = (JSONObject)new JSONParser().parse(expectedOutput);
+ // Do a REST call
+ ResteasyClient client = new ResteasyClientBuilder().build();
+ ResteasyWebTarget target = client.target("http://localhost:8080/api/valet/placement/v1/confirm-123/confirm1");
+ Response response = target.request().put(Entity.entity(input.toJSONString(), MediaType.APPLICATION_JSON));
+ String respnseData = response.readEntity(String.class);
+ response.close();
+ expectedOutput = ((JSONObject)((JSONObject)expectedOuptutJSON.get("values")).get("request")).toJSONString();
+ JSONObject responseDataJSON = (JSONObject)new JSONParser().parse(respnseData);
+ respnseData = ((JSONObject)responseDataJSON.get("values")).get("request").toString();
+ System.out.println("Expected :");
+ System.out.println(expectedOutput);
+ System.out.println("Actual :");
+ System.out.println(respnseData);
+ // Compare the outputs
+ JSONAssert.assertEquals(expectedOutput, respnseData, false);
+ }
+ }catch(Exception e) {
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+ }
+ @Test
+ public void testrollback1() throws Exception {
+ try(BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream("\\testing\\Rollback\\rollbackinput.txt")))) {
+ try(BufferedReader brOutput = new BufferedReader(new InputStreamReader(new FileInputStream("\\testing\\Rollback\\rollbackoutput.txt")))) {
+ JSONObject input = (JSONObject)new JSONParser().parse(br);
+ String expectedOutput = brOutput.readLine();
+ JSONObject expectedOuptutJSON = (JSONObject)new JSONParser().parse(expectedOutput);
+ // Do a REST call
+ ResteasyClient client = new ResteasyClientBuilder().build();
+ ResteasyWebTarget target = client.target("http://localhost:8080/api/valet/placement/v1/rollback-123/rollback1");
+ Response response = target.request().put(Entity.entity(input.toJSONString(), MediaType.APPLICATION_JSON));
+ String respnseData = response.readEntity(String.class);
+ response.close();
+ expectedOutput = ((JSONObject)((JSONObject)expectedOuptutJSON.get("values")).get("request")).toJSONString();
+ JSONObject responseDataJSON = (JSONObject)new JSONParser().parse(respnseData);
+ respnseData = ((JSONObject)responseDataJSON.get("values")).get("request").toString();
+ System.out.println("Expected :");
+ System.out.println(expectedOutput);
+ System.out.println("Actual :");
+ System.out.println(respnseData);
+ // Compare the outputs
+ JSONAssert.assertEquals(expectedOutput, respnseData, false);
+ }
+ }catch(Exception e) {
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+ }
+ @Test
+ public void testBodyVM2() throws Exception {
+ try(BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream("")))) {
+ JSONObject input = (JSONObject)new JSONParser().parse(br);
+ String expectedOutput = "[Expected output]";
+ // Do a REST call
+ ResteasyClient client = new ResteasyClientBuilder().build();
+ ResteasyWebTarget target = client.target("http://localhost:8080/api/valet/placement/v1/createVM2?requestId=12345");
+ Response response = target.request().post(Entity.entity(input.toJSONString(), MediaType.APPLICATION_JSON));
+ String respnseData = response.readEntity(String.class);
+ response.close();
+ System.out.println("Expected :");
+ System.out.println(expectedOutput);
+ System.out.println("Actual :");
+ System.out.println(respnseData);
+ // Compare the outputs
+ assertEquals(expectedOutput, respnseData);
+ }catch(Exception e) {
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+ }
+}*/
\ No newline at end of file diff --git a/valetapi/src/test/java/org/onap/fgps/controller/ValetServicePlacementControllerTest1.java b/valetapi/src/test/java/org/onap/fgps/controller/ValetServicePlacementControllerTest1.java new file mode 100644 index 0000000..91412bc --- /dev/null +++ b/valetapi/src/test/java/org/onap/fgps/controller/ValetServicePlacementControllerTest1.java @@ -0,0 +1,88 @@ +/* + * ============LICENSE_START========================================== + * ONAP - F-GPS API + * =================================================================== + * Copyright - 2019 ATT Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the "License"); + * you may not use this software 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. + * + * ============LICENSE_END============================================ + * + * + */ +package org.onap.fgps.controller;
+/*package com.valet.controller;
+
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+
+public class ValetServicePlacementControllerTest1 {
+
+ @Test
+ public void testValetServicePlacementController() {
+ fail("Not yet implemented");
+ }
+
+ @Test
+ public void testCreateVm() {
+ fail("Not yet implemented");
+ }
+
+ @Test
+ public void testUpdateVm() {
+ fail("Not yet implemented");
+ }
+
+ @Test
+ public void testDeleteVm() {
+ fail("Not yet implemented");
+ }
+
+ @Test
+ public void testConfirm() {
+ fail("Not yet implemented");
+ }
+
+ @Test
+ public void testRollback() {
+ fail("Not yet implemented");
+ }
+
+ @Test
+ public void testDummy() {
+ fail("Not yet implemented");
+ }
+
+ @Test
+ public void testDummy1() {
+ fail("Not yet implemented");
+ }
+
+}
+*/
\ No newline at end of file diff --git a/valetapi/src/test/java/org/onap/fgps/service/ValetGroupsServiceTest.java b/valetapi/src/test/java/org/onap/fgps/service/ValetGroupsServiceTest.java new file mode 100644 index 0000000..29e02b3 --- /dev/null +++ b/valetapi/src/test/java/org/onap/fgps/service/ValetGroupsServiceTest.java @@ -0,0 +1,103 @@ +/* + * ============LICENSE_START========================================== + * ONAP - F-GPS API + * =================================================================== + * Copyright © 2019 ATT Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the "License"); + * you may not use this software 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. + * + * ============LICENSE_END============================================ + * + * + */ +package org.onap.fgps.service;
+/*package com.valet.service;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.when;
+
+import org.json.simple.JSONObject;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.runners.MockitoJUnitRunner;
+
+import com.valet.beans.schema.Schema;
+import com.valet.dao.ValetServicePlacementDAO;
+
+@RunWith(MockitoJUnitRunner.class)
+public class ValetGroupsServiceTest {
+ @Mock
+ ValetServicePlacementDAO valetServicePlacementDAO;
+
+ @Mock
+ Schema schema;
+
+ @InjectMocks
+ ValetGroupsService valetGroupsService;
+
+ int WAIT_UNITL_SECONDS = 10;
+ int POLL_EVERY_SECONDS = 1;
+
+ @Test
+ public void saveGroupsRequest() {
+ JSONObject request = new JSONObject();
+ String operation = "test_operation";
+ String requestId = "req_id";
+ String expected = "test1";
+ String dbRequest = "dbRequest";
+ when(schema.formMsoInsertUpdateRequest(requestId, operation, operation + "-" + request.toJSONString()))
+ .thenReturn(dbRequest);
+ when(valetServicePlacementDAO.insertRow(dbRequest)).thenReturn(expected);
+ when(valetServicePlacementDAO.getRowFromResults(requestId)).thenReturn("");
+ when(valetServicePlacementDAO.deleteRowFromResults(requestId, dbRequest)).thenReturn("");
+
+ String actual = valetGroupsService.saveGroupsRequest(request, operation, requestId);
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public void pollForResult_result_at_first() {
+ JSONObject values = new JSONObject();
+ String requestId = "req_id";
+ when(valetServicePlacementDAO.getRowFromResults(requestId)).thenReturn("");
+ when(valetServicePlacementDAO.deleteRowFromResults(requestId, requestId)).thenReturn("");
+ valetGroupsService.pollForResult(values, requestId, WAIT_UNITL_SECONDS, POLL_EVERY_SECONDS);
+ }
+
+ @Test
+ public void pollForResult_result_not_got() {
+ JSONObject values = new JSONObject();
+ String requestId = "req_id";
+ when(valetServicePlacementDAO.getRowFromResults(requestId)).thenReturn(null);
+ valetGroupsService.pollForResult(values, requestId, WAIT_UNITL_SECONDS, POLL_EVERY_SECONDS);
+ }
+
+}
+*/
\ No newline at end of file diff --git a/valetapi/src/test/java/org/onap/fgps/service/ValetPlacementServiceTest.java b/valetapi/src/test/java/org/onap/fgps/service/ValetPlacementServiceTest.java new file mode 100644 index 0000000..d595de1 --- /dev/null +++ b/valetapi/src/test/java/org/onap/fgps/service/ValetPlacementServiceTest.java @@ -0,0 +1,335 @@ +/* + * ============LICENSE_START========================================== + * ONAP - F-GPS API + * =================================================================== + * Copyright © 2019 ATT Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the "License"); + * you may not use this software 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. + * + * ============LICENSE_END============================================ + * + * + */ +package org.onap.fgps.service;
+/*package com.valet.service;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.util.LinkedHashMap;
+
+import org.json.simple.JSONArray;
+import org.json.simple.JSONObject;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.runners.MockitoJUnitRunner;
+
+import com.valet.beans.schema.Schema;
+import com.valet.dao.ValetServicePlacementDAO;
+import com.valet.utils.Constants;
+
+@RunWith(MockitoJUnitRunner.class)
+public class ValetPlacementServiceTest {
+
+ @Mock
+ ValetServicePlacementDAO valetServicePlacementDAO;
+ @Mock
+ Schema schema;
+
+ @InjectMocks
+ ValetPlacementService valetPlacementService;
+
+ @Test
+ public void getParam_params_get_key_notnull() {
+ String key = "key";
+ JSONObject parameters = new JSONObject();
+ Object expected = new String("test1");
+ parameters.put("key", expected);
+ JSONObject envPrams = new JSONObject();
+ LinkedHashMap requestParameters = new LinkedHashMap<>();
+ Object actual = valetPlacementService.getParam(key, parameters, envPrams, requestParameters);
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public void getParam_env_get_key_null() {
+ String key = "key";
+ JSONObject parameters = new JSONObject();
+ Object expected = new String("test2");
+ parameters.put("key1", "val1");
+ JSONObject envPrams = new JSONObject();
+ envPrams.put("diffKey", "diffVal");
+ LinkedHashMap requestParameters = new LinkedHashMap<>();
+ requestParameters.put("key", expected);
+ Object actual = valetPlacementService.getParam(key, parameters, envPrams, requestParameters);
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public void getParam_env_get_key_notnull_length_0() {
+ String key = "key";
+ JSONObject parameters = new JSONObject();
+ Object expected = new String("test3");
+ parameters.put("key1", "val1");
+ JSONObject envPrams = new JSONObject();
+ envPrams.put("", "");
+ LinkedHashMap requestParameters = new LinkedHashMap<>();
+ requestParameters.put("key", expected);
+ Object actual = valetPlacementService.getParam(key, parameters, envPrams, requestParameters);
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public void getParam_env_get_key_notnull_length_not_0() {
+ String key = "key";
+ JSONObject parameters = new JSONObject();
+ Object expected = new String("test4");
+ parameters.put("key1", "val1");
+ JSONObject envPrams = new JSONObject();
+ envPrams.put("key", expected);
+ LinkedHashMap requestParameters = new LinkedHashMap<>();
+ Object actual = valetPlacementService.getParam(key, parameters, envPrams, requestParameters);
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public void getAttr() {
+ JSONArray key = new JSONArray();
+ key.add("jsonArray");
+ JSONObject resources = new JSONObject();
+ Object expected = new String("test5");
+ resources.put(key, expected);
+ Object actual = valetPlacementService.getAttr(key, resources);
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public void processTemplate_env_notnull() {
+ ValetPlacementService mockedValetPlacementService = mock(ValetPlacementService.class);
+ JSONObject template = new JSONObject();
+ JSONObject resources = new JSONObject();
+ JSONObject resourceObject = new JSONObject();
+ JSONObject properties = new JSONObject();
+ resourceObject.put(Constants.HEAT_REQUEST_PROPERTIES, properties);
+ resources.put("resourceObject", resourceObject);
+
+ template.put(Constants.VALET_REQUEST_RESOURCES, resources);
+ LinkedHashMap files = new LinkedHashMap<>();
+ JSONObject environment = new JSONObject();
+ JSONObject parameters = new JSONObject();
+ environment.put("parameters", parameters);
+ JSONObject parentProperties = new JSONObject();
+ LinkedHashMap requestParameters = new LinkedHashMap<>();
+ JSONObject expected = new JSONObject();
+ when(mockedValetPlacementService.parseResourceObject(template, null, resourceObject, parameters, files,
+ parentProperties, requestParameters)).thenReturn(expected);
+ when(mockedValetPlacementService.processTemplate(template, files, environment, parentProperties,
+ requestParameters)).thenCallRealMethod();
+
+ JSONObject actual = mockedValetPlacementService.processTemplate(template, files, environment, parentProperties,
+ requestParameters);
+ assertEquals(expected, actual.get("resourceObject"));
+ }
+
+ @Test
+ public void processTemplate_env_null() {
+ ValetPlacementService mockedValetPlacementService = mock(ValetPlacementService.class);
+ JSONObject template = new JSONObject();
+ JSONObject resources = new JSONObject();
+ JSONObject resourceObject = new JSONObject();
+ JSONObject properties = new JSONObject();
+ resourceObject.put(Constants.HEAT_REQUEST_PROPERTIES, properties);
+ resources.put("resourceObject", resourceObject);
+
+ template.put(Constants.VALET_REQUEST_RESOURCES, resources);
+ JSONObject parameters = new JSONObject();
+ template.put("parameters", parameters);
+ LinkedHashMap files = new LinkedHashMap<>();
+ JSONObject environment = null;
+ JSONObject parentProperties = new JSONObject();
+ LinkedHashMap requestParameters = new LinkedHashMap<>();
+ JSONObject expected = new JSONObject();
+ when(mockedValetPlacementService.parseResourceObject(template, null, resourceObject, parameters, files,
+ parentProperties, requestParameters)).thenReturn(expected);
+ when(mockedValetPlacementService.processTemplate(template, files, environment, parentProperties,
+ requestParameters)).thenCallRealMethod();
+
+ JSONObject actual = mockedValetPlacementService.processTemplate(template, files, environment, parentProperties,
+ requestParameters);
+ assertEquals(expected, actual.get("resourceObject"));
+ }
+
+ @Test
+ public void parseLogicFinal() {
+ assertNull(valetPlacementService.parseLogicFinal());
+ }
+
+ @Test
+ public void processMSORequest1_requestParameters_notnull() {
+ ValetPlacementService mockService = mock(ValetPlacementService.class);
+ JSONObject request = new JSONObject();
+ LinkedHashMap heat_request = new LinkedHashMap<>();
+ JSONObject template = new JSONObject();
+ template.put("templatekey", "templatevalue");
+ heat_request.put(Constants.HEAT_REQUEST_TEMPLATE, template);
+ LinkedHashMap files = new LinkedHashMap<>();
+ heat_request.put(Constants.HEAT_REQUEST_FILES, files);
+ JSONObject environment = new JSONObject();
+ heat_request.put(Constants.HEAT_REQUEST_ENVIRONMENT, environment);
+ LinkedHashMap requestParameters = new LinkedHashMap<>();
+ heat_request.put("parameters", requestParameters);
+ when(mockService.processMSORequest1(request)).thenCallRealMethod();
+ when(mockService.convertToJson(template.toString())).thenCallRealMethod();
+ when(mockService.convertToJson(environment.toString())).thenCallRealMethod();
+ JSONObject expected = new JSONObject();
+ expected.put("key", "value");
+ when(mockService.processTemplate(template, files, environment, null, requestParameters)).thenReturn(expected);
+
+ request.put(Constants.HEAT_REQUEST, heat_request);
+
+ String actual = mockService.processMSORequest1(request);
+ assertEquals(expected.toJSONString(), actual);
+ }
+
+ @Test
+ public void processMSORequest1_requestParameters_null() {
+ ValetPlacementService mockService = mock(ValetPlacementService.class);
+ JSONObject request = new JSONObject();
+ LinkedHashMap heat_request = new LinkedHashMap<>();
+ JSONObject template = new JSONObject();
+ template.put("templatekey", "templatevalue");
+ heat_request.put(Constants.HEAT_REQUEST_TEMPLATE, template);
+ LinkedHashMap files = new LinkedHashMap<>();
+ heat_request.put(Constants.HEAT_REQUEST_FILES, files);
+ JSONObject environment = new JSONObject();
+ heat_request.put(Constants.HEAT_REQUEST_ENVIRONMENT, environment);
+ LinkedHashMap requestParameters = null;
+ heat_request.put("parameters", requestParameters);
+ when(mockService.processMSORequest1(request)).thenCallRealMethod();
+ when(mockService.convertToJson(template.toString())).thenCallRealMethod();
+ when(mockService.convertToJson(environment.toString())).thenCallRealMethod();
+ JSONObject expected = new JSONObject();
+ expected.put("key", "value");
+ org.mockito.Mockito.when(mockService.processTemplate(any(), any(), any(), any(), any())).thenReturn(expected);
+
+ request.put(Constants.HEAT_REQUEST, heat_request);
+
+ String actual = mockService.processMSORequest1(request);
+ assertEquals(expected.toJSONString(), actual);
+ }
+
+ @Test
+ public void processMSORequest1_exception() {
+ ValetPlacementService mockService = mock(ValetPlacementService.class);
+ JSONObject request = new JSONObject();
+ LinkedHashMap heat_request = new LinkedHashMap<>();
+ JSONObject template = new JSONObject();
+ template.put("templatekey", "templatevalue");
+ heat_request.put(Constants.HEAT_REQUEST_TEMPLATE, template);
+ LinkedHashMap files = new LinkedHashMap<>();
+ heat_request.put(Constants.HEAT_REQUEST_FILES, files);
+ JSONObject environment = new JSONObject();
+ heat_request.put(Constants.HEAT_REQUEST_ENVIRONMENT, environment);
+ LinkedHashMap requestParameters = null;
+ heat_request.put("parameters", requestParameters);
+ when(mockService.processMSORequest1(request)).thenCallRealMethod();
+ when(mockService.convertToJson(template.toString())).thenCallRealMethod();
+ when(mockService.convertToJson(environment.toString())).thenCallRealMethod();
+ JSONObject expected = new JSONObject();
+ expected.put("key", "value");
+ org.mockito.Mockito.when(mockService.processTemplate(any(), any(), any(), any(), any()))
+ .thenThrow(Exception.class);
+
+ request.put(Constants.HEAT_REQUEST, heat_request);
+
+ String actual = mockService.processMSORequest1(request);
+ assertNull(actual);
+ }
+
+ @Test
+ public void convertToJson() {
+ String data = "{\"key\":\"value\"}";
+ JSONObject actual = valetPlacementService.convertToJson(data);
+ assertEquals("value", actual.get("key"));
+ }
+
+ @Test
+ public void convertToJson_exception() {
+ String data = "{\"key\"::\"value\"}";
+ JSONObject actual = valetPlacementService.convertToJson(data);
+ assertNull(actual);
+ }
+
+ @Test
+ public void processDeleteRequest() {
+ String requestId = "req_id";
+ JSONObject request = new JSONObject();
+ String dbRequest = "dbRequest";
+ when(schema.formMsoInsertUpdateRequest(requestId, "delete", request.toJSONString())).thenReturn(dbRequest);
+ when(valetServicePlacementDAO.insertRow(dbRequest)).thenReturn(requestId);
+ String actual = valetPlacementService.processDeleteRequest(request, requestId);
+ assertEquals(requestId, actual);
+ }
+
+ @Test
+ public void saveRequest() {
+ String requestId = "req_id";
+ JSONObject request = new JSONObject();
+ String dbRequest = "dbRequest";
+ String operation = "operation";
+ when(schema.formMsoInsertUpdateRequest(requestId, operation, request.toJSONString())).thenReturn(dbRequest);
+ when(valetServicePlacementDAO.insertRow(dbRequest)).thenReturn(requestId);
+ when(valetServicePlacementDAO.getRowFromResults(requestId)).thenReturn("");
+ when(valetServicePlacementDAO.deleteRowFromResults(requestId, operation)).thenReturn("");
+ String actual = valetPlacementService.saveRequest(request, operation, requestId);
+ assertEquals(requestId, actual);
+ }
+
+ @Test
+ public void pollForResult_result_at_first() {
+ JSONObject values = new JSONObject();
+ String requestId = "req_id";
+ when(valetServicePlacementDAO.getRowFromResults(requestId)).thenReturn("");
+ when(valetServicePlacementDAO.deleteRowFromResults(requestId, requestId)).thenReturn("");
+ valetPlacementService.pollForResult(values, requestId, 10, 1);
+ }
+
+ @Test
+ public void pollForResult_result_not_got() {
+ JSONObject values = new JSONObject();
+ String requestId = "req_id";
+ when(valetServicePlacementDAO.getRowFromResults(requestId)).thenReturn(null);
+ valetPlacementService.pollForResult(values, requestId, 5, 1);
+ }
+}
+*/
\ No newline at end of file diff --git a/valetapi/src/test/resources/application-test.properties b/valetapi/src/test/resources/application-test.properties new file mode 100755 index 0000000..35c9fa2 --- /dev/null +++ b/valetapi/src/test/resources/application-test.properties @@ -0,0 +1,37 @@ + +# ============LICENSE_START======================================================= +# ONAP - F-GPS +# ================================================================================ +# Copyright (C) 2019 AT&T Intellectual Property. 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============================================ +# =================================================================== +# +### + +info.build.artifact=@project.artifactId@ +info.build.name=@project.name@ +info.build.description=@project.description@ +info.build.version=@project.version@ + +spring.jersey.type=filter + +logging.level.root=info +logging.level.org.glassfish=info +logging.level.org.glassfish.jersey=info + +spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration,org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration + +logging.pattern.console=%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(%5p) %clr($ threadId: {PID:- }){magenta} %clr(---){faint} %clr([ hostname: %X{hostname} serviceName: %X{serviceName} version: %X{version} transactionId: %X{transactionId} requestTimeStamp: %X{requestTimestamp} responseTimeStamp: %X{responseTimestamp} duration: %X{duration}]){yellow} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n%wex
\ No newline at end of file |