--- /dev/null
+/* Copyright (c) 2019 AT&T Intellectual Property. #\r
+# #\r
+# Licensed under the Apache License, Version 2.0 (the "License"); #\r
+# you may not use this file except in compliance with the License. #\r
+# You may obtain a copy of the License at #\r
+# #\r
+# http://www.apache.org/licenses/LICENSE-2.0 #\r
+# #\r
+# Unless required by applicable law or agreed to in writing, software #\r
+# distributed under the License is distributed on an "AS IS" BASIS, #\r
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #\r
+# See the License for the specific language governing permissions and #\r
+# limitations under the License. #\r
+##############################################################################*/\r
+\r
+\r
+package org.oran.otf.api.tests.integration.services;\r
+\r
+import static org.hamcrest.CoreMatchers.containsString;\r
+import static org.hamcrest.CoreMatchers.equalTo;\r
+\r
+import org.oran.otf.api.Application;\r
+import org.oran.otf.api.tests.shared.MemoryDatabase;\r
+import org.oran.otf.common.model.TestDefinition;\r
+import org.oran.otf.common.model.TestInstance;\r
+import org.oran.otf.common.model.User;\r
+import io.restassured.RestAssured;\r
+import org.eclipse.jetty.http.QuotedQualityCSV;\r
+import org.junit.AfterClass;\r
+import org.junit.Before;\r
+import org.junit.BeforeClass;\r
+import org.junit.Test;\r
+import org.junit.runner.RunWith;\r
+import org.springframework.beans.factory.annotation.Autowired;\r
+import org.springframework.beans.factory.annotation.Value;\r
+import org.springframework.boot.autoconfigure.EnableAutoConfiguration;\r
+import org.springframework.boot.test.context.SpringBootTest;\r
+import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;\r
+import org.springframework.boot.web.server.LocalServerPort;\r
+import org.springframework.data.mongodb.core.MongoTemplate;\r
+import org.springframework.data.mongodb.core.query.Criteria;\r
+import org.springframework.data.mongodb.core.query.Query;\r
+import org.springframework.test.context.ActiveProfiles;\r
+import org.springframework.test.context.TestPropertySource;\r
+import org.springframework.test.context.junit4.SpringRunner;\r
+\r
+@RunWith(SpringRunner.class)\r
+@SpringBootTest(\r
+ webEnvironment = WebEnvironment.RANDOM_PORT,\r
+ classes = {Application.class}\r
+)\r
+@TestPropertySource("classpath:application-test.properties")\r
+@ActiveProfiles("test")\r
+public class InstanceServiceRouteIT {\r
+ @LocalServerPort\r
+ private int port;\r
+ @Value("${otf.mechid}")\r
+ private String username;\r
+ @Value("${otf.mechpass}")\r
+ private String password;\r
+ private static User mechUser;\r
+\r
+ @Autowired\r
+ private MongoTemplate mongoTemplate;\r
+\r
+ @BeforeClass\r
+ public static void setup() throws Exception{\r
+ MemoryDatabase.createAllTables();\r
+ MemoryDatabase.createAllAdmin();\r
+ //mechUser = MemoryDatabase.createMechUser();\r
+ }\r
+ @AfterClass\r
+ public static void cleanup(){\r
+ MemoryDatabase.cleanup();\r
+ }\r
+ @Before\r
+ public void setupRestAssured() {\r
+ RestAssured.port = port;\r
+ RestAssured.urlEncodingEnabled = false;\r
+ RestAssured.baseURI = "https://localhost";\r
+ RestAssured.basePath="/otf/api/testInstance";\r
+ RestAssured.useRelaxedHTTPSValidation();\r
+ }\r
+ //NoAuth Tests\r
+\r
+ @Test\r
+ public void testFindByIdRespondsWith401OnNoAuth(){\r
+ RestAssured.given().log().all().header("Accept", "application/json").get("/v1/id/abced").then().assertThat().statusCode(401);\r
+ }\r
+ @Test\r
+ public void testFindByProcessKeyRespondsWith401OnNoAuth(){\r
+ RestAssured.given().log().all().header("Accept", "application/json").get("/v1/processDefinitionKey/abced").then().assertThat().statusCode(401);\r
+ }\r
+ @Test\r
+ public void testFindByProcessKeyAndVersionRespondsWith401OnNoAuth(){\r
+ RestAssured.given().log().all().header("Accept", "application/json").get("/v1/processDefinitionKey/abced/version/1").then().assertThat().statusCode(401);\r
+ }\r
+\r
+\r
+ @Test\r
+ public void testExecuteRespondsWith401OnNoAuth(){\r
+ RestAssured.given().log().all().header("Accept", "application/json").get("/execute/v1/id/abced/").then().assertThat().statusCode(401);\r
+ }\r
+\r
+\r
+ @Test\r
+ public void testCreateByTestDefinitionIdRespondsWith401OnNoAuth(){\r
+ RestAssured.given().log().all().header("Accept", "application/json").get("/create/v1/testDefinitionId/abced/").then().assertThat().statusCode(401);\r
+ }\r
+ @Test\r
+ public void testCreateByTestDefinitionIdAndVersionRespondsWith401OnNoAuth(){\r
+ RestAssured.given().log().all().header("Accept", "application/json").get("/create/v1/testDefinitionId/abced/version/2").then().assertThat().statusCode(401);\r
+ }\r
+ @Test\r
+ public void testCreateByProcessDefinitionKeyRespondsWith401OnNoAuth(){\r
+ RestAssured.given().log().all().header("Accept", "application/json").get("/create/v1/processDefinitionKey/abced").then().assertThat().statusCode(401);\r
+ }\r
+ @Test\r
+ public void testCreateByProcessDefinitionKeyAndVersionRespondsWith401OnNoAuth(){\r
+ RestAssured.given().log().all().header("Accept", "application/json").get("/create/v1/processDefinitionKey/abced/version/2").then().assertThat().statusCode(401);\r
+ }\r
+\r
+ //With Auth and Wrong id\r
+ @Test\r
+ public void testFindByIdRespondsWith400OnWrongId(){\r
+ RestAssured.given().auth().basic(username,password).log().all().header("Accept", "application/json").get("/v1/id/abced").then().assertThat().statusCode(400);\r
+ }\r
+ @Test\r
+ public void testFindByIdRespondsWithMessageOnWrongId(){\r
+ RestAssured.given().auth().basic(username,password).log().all().header("Accept", "application/json").get("/v1/id/abcde").then().assertThat().body("message", containsString("is not a valid ObjectId (BSON)"));\r
+ }\r
+ @Test\r
+ public void testFindByProcessDefinitionRespondsWith400OnWrongProcessDefinition(){\r
+ TestDefinition testDefinition = mongoTemplate.findOne(new Query(Criteria.where("testName").is("testDef1")), TestDefinition.class);\r
+ RestAssured.given().auth().basic(username,password).log().all().header("Accept", "*/*").get("/v1/processDefinitionKey/"+testDefinition.getProcessDefinitionKey()).then().assertThat().statusCode(400);\r
+ }\r
+ @Test\r
+ public void testFindByProcessDefinitionRespondsWithMessageOnWrongProcessDefinition(){\r
+ TestDefinition testDefinition = mongoTemplate.findOne(new Query(Criteria.where("testName").is("testDef1")), TestDefinition.class);\r
+ RestAssured.given().auth().basic(username,password).log().all().header("Accept", "application/json").get("/v1/processDefinitionKey/"+testDefinition.getProcessDefinitionKey()).then().assertThat().body("message", containsString("No test instances found"));\r
+ }\r
+\r
+ //Successful Get Methods\r
+\r
+ @Test\r
+ public void testFindByIdRespondsWith200OnSuccess(){\r
+ TestInstance testInstance = mongoTemplate.findOne(new Query(Criteria.where("testInstanceName").is("MechTestInstance")), TestInstance.class);\r
+ RestAssured.given().auth().basic(username,password).log().all().header("Accept", "*/*").get("/v1/id/"+testInstance.get_id()).then().assertThat().statusCode(200);\r
+ }\r
+\r
+ @Test\r
+ public void testFindByProcessDefinitionKeyRespondsWith200OnSuccess(){\r
+ TestDefinition testDefinition = mongoTemplate.findOne(new Query(Criteria.where("testName").is("MechTestDefinition")), TestDefinition.class);\r
+ RestAssured.given().auth().basic(username, password).log().all().header("Accept", "*/*").get("/v1/processDefinitionKey/"+testDefinition.getProcessDefinitionKey()).then().assertThat().statusCode(200);\r
+ }\r
+\r
+ @Test\r
+ public void testFindByProcessDefinitionKeyAndVersionRespondsWith200OnSuccess(){\r
+ TestDefinition testDefinition = mongoTemplate.findOne(new Query(Criteria.where("testName").is("MechTestDefinition")), TestDefinition.class);\r
+ RestAssured.given().auth().basic(username, password).log().all().header("Accept", "*/*").get("/v1/processDefinitionKey/"+testDefinition.getProcessDefinitionKey()+"/version/"+1).then().assertThat().statusCode(200);\r
+ }\r
+\r
+ @Test\r
+ public void testCreateByTestDefinitionIdRespondsWith201OnSuccess(){\r
+ TestDefinition testDefinition = mongoTemplate.findOne(new Query(Criteria.where("testName").is("MechTestDefinition")), TestDefinition.class);\r
+ System.out.println(testDefinition.getBpmnInstances());\r
+ RestAssured.given().contentType("application/json\r\n").auth().basic(username, password).log().all().header("Accept", "*/*").post("/create/v1/testDefinitionId/"+testDefinition.get_id()+"/version/"+1).then().assertThat().statusCode(404);\r
+ }\r
+\r
+}\r