summaryrefslogtreecommitdiffstats
path: root/javatoscachecker/service/src
diff options
context:
space:
mode:
Diffstat (limited to 'javatoscachecker/service/src')
-rw-r--r--javatoscachecker/service/src/test/java/org/onap/tosca/checker/service/test/CheckerServiceTest.java151
-rw-r--r--javatoscachecker/service/src/test/resources/standalone.yaml21
-rw-r--r--javatoscachecker/service/src/test/resources/standalone_with_errors.yaml23
-rw-r--r--javatoscachecker/service/src/test/resources/test_schema.yaml17
-rw-r--r--javatoscachecker/service/src/test/resources/test_template.yaml11
5 files changed, 223 insertions, 0 deletions
diff --git a/javatoscachecker/service/src/test/java/org/onap/tosca/checker/service/test/CheckerServiceTest.java b/javatoscachecker/service/src/test/java/org/onap/tosca/checker/service/test/CheckerServiceTest.java
new file mode 100644
index 0000000..b6eb644
--- /dev/null
+++ b/javatoscachecker/service/src/test/java/org/onap/tosca/checker/service/test/CheckerServiceTest.java
@@ -0,0 +1,151 @@
+/*
+ * Copyright (c) 2017 <AT&T>. 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.
+ */
+package org.onap.tosca.checker.service.test;
+
+import java.util.Scanner;
+
+import static org.junit.Assert.assertTrue;
+import static org.assertj.core.api.Assertions.assertThat;
+
+import org.junit.FixMethodOrder;
+import org.junit.runners.MethodSorters;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
+import org.springframework.test.context.junit4.SpringRunner;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import org.springframework.test.context.web.WebAppConfiguration;
+import org.springframework.boot.test.web.client.TestRestTemplate;
+
+import org.springframework.http.HttpMethod;
+import org.springframework.http.MediaType;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpEntity;
+import org.springframework.http.ResponseEntity;
+
+import org.onap.tosca.checker.Report;
+
+/**
+ * The test order is relevant here ..
+ */
+
+//@RunWith(SpringJUnit4ClassRunner.class)
+@RunWith(SpringRunner.class)
+@SpringBootTest(classes = org.onap.tosca.checker.service.CheckerEngine.class,
+ webEnvironment = WebEnvironment.RANDOM_PORT)
+@FixMethodOrder(MethodSorters.NAME_ASCENDING)
+public class CheckerServiceTest {
+
+ @Autowired
+ private TestRestTemplate restTemplate;
+
+ @Test
+ public void testCatalogExists() {
+ assertTrue(
+ this.restTemplate.getForEntity("/check_template/nosuchcatalog", String.class)
+ .getStatusCodeValue() == 404);
+ }
+
+ @Test
+ public void testStandaloneTemplate() {
+
+ ResponseEntity<Report> response =
+ this.restTemplate.exchange("/check_template/", HttpMethod.POST, prepareRequest("standalone.yaml"), Report.class);
+
+ assertTrue(response.getStatusCodeValue() == 200);
+ assertTrue(response.getBody().size() == 0); //no errors
+ }
+
+ @Test
+ public void testStandaloneTemplateWithErrors() {
+
+ ResponseEntity<Report> response =
+ this.restTemplate.exchange("/check_template/", HttpMethod.POST, prepareRequest("standalone_with_errors.yaml"), Report.class);
+
+ assertTrue(response.getStatusCodeValue() == 200);
+ assertTrue(response.getBody().size() > 0); //some errors
+ }
+
+ @Test
+ public void testCatalog1WithNamedTemplate() {
+
+ ResponseEntity<Report> response =
+ this.restTemplate.exchange("/check_template/test/schema.yaml", HttpMethod.POST, prepareRequest("test_schema.yaml"), Report.class);
+
+ assertTrue(response.getStatusCodeValue() == 200);
+ assertThat(response.getBody().size() == 0)
+ .as("Processing failed: " + response.getBody())
+ .isTrue();
+ }
+
+ @Test
+ public void testCatalog2WithTemplate() {
+
+ ResponseEntity<Report> response =
+ this.restTemplate.exchange("/check_template/test/", HttpMethod.POST, prepareRequest("test_template.yaml"), Report.class);
+
+ assertTrue(response.getStatusCodeValue() == 200);
+ assertThat(response.getBody().size() == 0)
+ .as("Processing failed: " + response.getBody())
+ .isTrue();
+ }
+
+ @Test
+ public void testCatalog3NamedTemplateExists() {
+
+ ResponseEntity<String> response =
+ this.restTemplate.exchange("/check_template/test/schema.yaml", HttpMethod.GET, null, String.class);
+
+ assertTrue(response.getStatusCodeValue() == 200);
+ }
+
+ @Test
+ public void testCatalog4NamedTemplateDoesNotExists() {
+ ResponseEntity<String> response =
+ this.restTemplate.exchange("/check_template/test/test_schema.yaml", HttpMethod.GET, null, String.class);
+
+ assertTrue(response.getStatusCodeValue() == 404);
+ }
+
+ @Test
+ public void testCatalog5NamedTemplateDoesNotExists() {
+ ResponseEntity<String> response =
+ this.restTemplate.exchange("/check_template/test/test_schema.yaml", HttpMethod.GET, null, String.class);
+
+ assertThat(response.getStatusCodeValue() == 404)
+ .as("Existence check failed, got " + response.getStatusCodeValue())
+ .isTrue();
+ }
+
+ @Test
+ public void testCatalog6Delete() {
+ ResponseEntity<String> response =
+ this.restTemplate.exchange("/check_template/test/", HttpMethod.DELETE, null, String.class);
+
+ assertThat(response.getStatusCodeValue() == 200)
+ .as("Existence check failed, got " + response.getStatusCodeValue())
+ .isTrue();
+ }
+
+ private HttpEntity prepareRequest(String theResourceName) {
+ String content = new Scanner(
+ Thread.currentThread().getContextClassLoader().getResourceAsStream(theResourceName), "UTF-8")
+ .useDelimiter("\\Z").next();
+
+ HttpHeaders headers = new HttpHeaders();
+ headers.setContentType(MediaType.APPLICATION_JSON);
+ return new HttpEntity<String>(content, headers);
+ }
+}
diff --git a/javatoscachecker/service/src/test/resources/standalone.yaml b/javatoscachecker/service/src/test/resources/standalone.yaml
new file mode 100644
index 0000000..26797ab
--- /dev/null
+++ b/javatoscachecker/service/src/test/resources/standalone.yaml
@@ -0,0 +1,21 @@
+tosca_definitions_version: tosca_simple_yaml_1_0
+
+topology_template:
+ node_templates:
+ my_server:
+ type: tosca.nodes.Compute
+ capabilities:
+ # Host container properties
+ host:
+ properties:
+ num_cpus: 1
+ disk_size: 10 GB
+ mem_size: 4096 MB
+ # Guest Operating System properties
+ os:
+ properties:
+ # host Operating System image properties
+ architecture: x86_64
+ type: linux
+ distribution: rhel
+ version: 6.5
diff --git a/javatoscachecker/service/src/test/resources/standalone_with_errors.yaml b/javatoscachecker/service/src/test/resources/standalone_with_errors.yaml
new file mode 100644
index 0000000..d5c1a15
--- /dev/null
+++ b/javatoscachecker/service/src/test/resources/standalone_with_errors.yaml
@@ -0,0 +1,23 @@
+tosca_definitions_version: tosca_simple_yaml_1_0
+description: uses unknown capability propertya to trigger an error
+
+topology_template:
+ node_templates:
+ my_server:
+ type: tosca.nodes.Compute
+ capabilities:
+ # Host container properties
+ host:
+ properties:
+ num_cpus: 1
+ disk_size: 10 GB
+ mem_size: 4096 MB
+ virtualization_support: true
+ # Guest Operating System properties
+ os:
+ properties:
+ # host Operating System image properties
+ architecture: x86_64
+ type: linux
+ distribution: rhel
+ version: 6.5
diff --git a/javatoscachecker/service/src/test/resources/test_schema.yaml b/javatoscachecker/service/src/test/resources/test_schema.yaml
new file mode 100644
index 0000000..9575e27
--- /dev/null
+++ b/javatoscachecker/service/src/test/resources/test_schema.yaml
@@ -0,0 +1,17 @@
+tosca_definitions_version: tosca_simple_yaml_1_1
+
+data_types:
+ org.onap.tosca.checker.service.Person:
+ properties:
+ firstName:
+ type: string
+ required: true
+ lastName:
+ type: string
+ required: true
+
+node_types:
+ org.onap.tosca.checker.service.Residence:
+ properties:
+ owner:
+ type: org.onap.tosca.checker.service.Person
diff --git a/javatoscachecker/service/src/test/resources/test_template.yaml b/javatoscachecker/service/src/test/resources/test_template.yaml
new file mode 100644
index 0000000..478aec0
--- /dev/null
+++ b/javatoscachecker/service/src/test/resources/test_template.yaml
@@ -0,0 +1,11 @@
+tosca_definitions_version: tosca_simple_yaml_1_0
+
+imports:
+ - schema: schema.yaml
+
+topology_template:
+ node_templates:
+ my_house:
+ type: org.onap.tosca.checker.service.Residence
+ properties:
+ owner: {firstName: "Serban", lastName: "Jora"}