1 /*******************************************************************************
2 * Copyright (c) 2012-2013 University of Stuttgart.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * and the Apache License 2.0 which both accompany this distribution,
6 * and are available at http://www.eclipse.org/legal/epl-v10.html
7 * and http://www.apache.org/licenses/LICENSE-2.0
10 * Oliver Kopp - initial API and implementation
11 *******************************************************************************/
12 package org.eclipse.winery.repository.resources.entitytypes.nodetypes.reqandcapdefs;
14 import javax.ws.rs.core.MediaType;
16 import org.hamcrest.Matchers;
17 import org.junit.Assert;
18 import org.junit.BeforeClass;
19 import org.junit.FixMethodOrder;
20 import org.junit.Test;
21 import org.junit.runners.MethodSorters;
22 import org.eclipse.winery.repository.PrefsTestEnabledGitBackedRepository;
23 import org.eclipse.winery.repository.backend.Repository;
24 import org.eclipse.winery.repository.backend.filebased.GitBasedRepository;
26 import com.jayway.restassured.RestAssured;
27 import com.jayway.restassured.http.ContentType;
28 import com.jayway.restassured.path.json.JsonPath;
29 import com.jayway.restassured.response.Response;
34 * import static com.jayway.restassured.RestAssured.*; import static
35 * com.jayway.restassured.matcher.RestAssuredMatchers.*; import static
36 * org.hamcrest.Matchers.*; import static
37 * com.jayway.restassured.path.json.JsonPath.*;
42 * REST-based testing of requirement definitions
44 * We use a fixed method sort order as we create resources in one test and work
45 * with them in the next step
47 @FixMethodOrder(MethodSorters.NAME_ASCENDING)
48 public class TestRequirementDefinitions {
51 public static void init() throws Exception {
52 // enable git-backed repository
53 new PrefsTestEnabledGitBackedRepository();
55 // we use a half-filled repository
56 ((GitBasedRepository) Repository.INSTANCE).setRevisionTo("97fa997b92965d8bc84e86274b0203f1db7495c5");
58 // we test on the Amazon EC2 node type
59 // could be any other node type without requirement definitions
61 // the following URI is already encoded (copied from the browser URL field)
62 RestAssured.urlEncodingEnabled = false;
63 RestAssured.basePath = "/org.eclipse.winery.repository/nodetypes/http%253A%252F%252Fwww.example.org%252Ftosca%252Fnodetypes/Amazon_EC2/requirementdefinitions";
67 public void test01_NoRequirementDefinitions() throws Exception {
69 .header("Accept", MediaType.APPLICATION_JSON)
71 .body(Matchers.equalTo("[]"))
77 public void test02_CreateRequirementDefinition() throws Exception {
79 .parameter("name", "test")
87 public void test03_NoConstraints() throws Exception {
89 .header("Accept", MediaType.APPLICATION_JSON)
91 .body(Matchers.equalTo("[]"))
93 .get("test/constraints/");
97 public void test04_CreateConstraint() throws Exception {
99 .body("<tosca:Constraint xmlns:tosca=\"http://docs.oasis-open.org/tosca/ns/2011/12\" xmlns:winery=\"http://www.opentosca.org/winery/extensions/tosca/2013/02/12\" constraintType=\"http://www.example.org/constrainttype\"/>")
100 .contentType(ContentType.XML)
103 .body(Matchers.notNullValue())
105 .post("test/constraints/");
109 public void test05_GetConstraint() throws Exception {
110 Response response = RestAssured
112 .header("Accept", MediaType.APPLICATION_JSON)
116 .get("test/constraints/");
119 JsonPath jsonPath = JsonPath.from(response.asString());
121 Assert.assertEquals("One id", jsonPath.getList("").size(), 1);
123 String id = jsonPath.getString("[0]");
125 // TODO: check content
128 .header("Accept", MediaType.TEXT_XML)
132 .get("test/constraints/{id}/", id);
134 // we also test the sub resource here
135 // otherwise we had to transport the id throught the code via a global variable
139 .body(Matchers.is("http://www.example.org/constrainttype"))
141 .get("test/constraints/{id}/type", id);