aboutsummaryrefslogtreecommitdiffstats
path: root/winery/org.eclipse.winery.repository/src/test/java/org/eclipse
diff options
context:
space:
mode:
authorhuangjian <huang.jian12@zte.com.cn>2016-08-31 16:47:33 +0800
committerhuangjian <huang.jian12@zte.com.cn>2016-08-31 16:47:33 +0800
commitfa49e78cc199526a9e33b59c5194f8e3bf0f0952 (patch)
tree3478e867a8f304266dbceca6e992cceca410ede4 /winery/org.eclipse.winery.repository/src/test/java/org/eclipse
parent159d40f0011559c8f82338b29dca1bffd700f2c8 (diff)
Add winery source code
Change-Id: I1c5088121d79b71098c3cba1996c6f784737532e Issue-id: TOSCA-49 Signed-off-by: huangjian <huang.jian12@zte.com.cn>
Diffstat (limited to 'winery/org.eclipse.winery.repository/src/test/java/org/eclipse')
-rw-r--r--winery/org.eclipse.winery.repository/src/test/java/org/eclipse/winery/librarytests/DateTest.java33
-rw-r--r--winery/org.eclipse.winery.repository/src/test/java/org/eclipse/winery/librarytests/InheritanceIllustration.java48
-rw-r--r--winery/org.eclipse.winery.repository/src/test/java/org/eclipse/winery/repository/PrefsTestEnabled.java32
-rw-r--r--winery/org.eclipse.winery.repository/src/test/java/org/eclipse/winery/repository/PrefsTestEnabledGitBackedRepository.java30
-rw-r--r--winery/org.eclipse.winery.repository/src/test/java/org/eclipse/winery/repository/PrefsTestEnabledUsingConfiguredRepository.java28
-rw-r--r--winery/org.eclipse.winery.repository/src/test/java/org/eclipse/winery/repository/TestWithRepositoryConnection.java27
-rw-r--r--winery/org.eclipse.winery.repository/src/test/java/org/eclipse/winery/repository/UtilsTest.java26
-rw-r--r--winery/org.eclipse.winery.repository/src/test/java/org/eclipse/winery/repository/export/TestToscaExporter.java81
-rw-r--r--winery/org.eclipse.winery.repository/src/test/java/org/eclipse/winery/repository/importing/TestCSARImporter.java48
-rw-r--r--winery/org.eclipse.winery.repository/src/test/java/org/eclipse/winery/repository/resources/TestAbstractComponentInstanceResourceDefinitionsBacked.java54
-rw-r--r--winery/org.eclipse.winery.repository/src/test/java/org/eclipse/winery/repository/resources/TestResource.java22
-rw-r--r--winery/org.eclipse.winery.repository/src/test/java/org/eclipse/winery/repository/resources/entitytemplates/artifacttemplates/TestArtifactTemplateResource.java43
-rw-r--r--winery/org.eclipse.winery.repository/src/test/java/org/eclipse/winery/repository/resources/entitytypes/capabilitytypes/TestCapabilityTypeResource.java53
-rw-r--r--winery/org.eclipse.winery.repository/src/test/java/org/eclipse/winery/repository/resources/entitytypes/nodetypes/reqandcapdefs/TestRequirementDefinitions.java144
14 files changed, 669 insertions, 0 deletions
diff --git a/winery/org.eclipse.winery.repository/src/test/java/org/eclipse/winery/librarytests/DateTest.java b/winery/org.eclipse.winery.repository/src/test/java/org/eclipse/winery/librarytests/DateTest.java
new file mode 100644
index 0000000..db4aea4
--- /dev/null
+++ b/winery/org.eclipse.winery.repository/src/test/java/org/eclipse/winery/librarytests/DateTest.java
@@ -0,0 +1,33 @@
+/*******************************************************************************
+ * Copyright (c) 2012-2013 University of Stuttgart.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * and the Apache License 2.0 which both accompany this distribution,
+ * and are available at http://www.eclipse.org/legal/epl-v10.html
+ * and http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Contributors:
+ * Oliver Kopp - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.winery.librarytests;
+
+import java.text.ParseException;
+import java.util.Date;
+import java.util.Locale;
+
+import org.apache.commons.lang3.time.DateUtils;
+
+/**
+ * Date parsing test, when the system locale is not ENGLISH
+ */
+public class DateTest {
+
+ public static void main(String[] args) throws ParseException {
+ // In case the following line is commented, this method throws a ParseException
+ Locale.setDefault(Locale.ENGLISH);
+ String modified = "Fri, 23 Mar 2012 11:04:56 GMT";
+ Date modifiedDate = DateUtils.parseDate(modified, org.apache.http.impl.cookie.DateUtils.DEFAULT_PATTERNS);
+ System.out.println(modifiedDate);
+ }
+
+}
diff --git a/winery/org.eclipse.winery.repository/src/test/java/org/eclipse/winery/librarytests/InheritanceIllustration.java b/winery/org.eclipse.winery.repository/src/test/java/org/eclipse/winery/librarytests/InheritanceIllustration.java
new file mode 100644
index 0000000..95601d7
--- /dev/null
+++ b/winery/org.eclipse.winery.repository/src/test/java/org/eclipse/winery/librarytests/InheritanceIllustration.java
@@ -0,0 +1,48 @@
+/*******************************************************************************
+ * Copyright (c) 2012-2013 University of Stuttgart.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * and the Apache License 2.0 which both accompany this distribution,
+ * and are available at http://www.eclipse.org/legal/epl-v10.html
+ * and http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Contributors:
+ * Oliver Kopp - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.winery.librarytests;
+/**
+ * This class is intended to demonstrate static resolution of overloaded methods
+ *
+ * The output of this class is "Doing sth. with a followed by "Doing sth. with
+ * b" even if the passed "theObject" is of type B
+ */
+public class InheritanceIllustration {
+
+ private static class A {
+ };
+
+ private static class B extends A {
+ };
+
+ private static class X {
+
+ public static void doSomething(A a) {
+ System.out.println("Doing sth. with a");
+ }
+
+ public static void doSomething(B b) {
+ System.out.println("Doing sth. with b");
+ }
+ }
+
+
+ /**
+ * @param args
+ */
+ public static void main(String[] args) {
+ A theObject = new B();
+ X.doSomething(theObject);
+ X.doSomething((B) theObject);
+ }
+
+}
diff --git a/winery/org.eclipse.winery.repository/src/test/java/org/eclipse/winery/repository/PrefsTestEnabled.java b/winery/org.eclipse.winery.repository/src/test/java/org/eclipse/winery/repository/PrefsTestEnabled.java
new file mode 100644
index 0000000..3e48592
--- /dev/null
+++ b/winery/org.eclipse.winery.repository/src/test/java/org/eclipse/winery/repository/PrefsTestEnabled.java
@@ -0,0 +1,32 @@
+/*******************************************************************************
+ * Copyright (c) 2012-2013 University of Stuttgart.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * and the Apache License 2.0 which both accompany this distribution,
+ * and are available at http://www.eclipse.org/legal/epl-v10.html
+ * and http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Contributors:
+ * Oliver Kopp - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.winery.repository;
+
+import java.io.IOException;
+
+public abstract class PrefsTestEnabled extends Prefs {
+
+ /**
+ * @param initializeRepository true if the repository should be initialized
+ * as provided in winery.properties
+ * @throws IOException
+ */
+ protected PrefsTestEnabled(boolean initializeRepository) throws IOException {
+ super(initializeRepository);
+ }
+
+ @Override
+ public String getResourcePath() {
+ return "http://www.example.org/winery/test";
+ }
+
+}
diff --git a/winery/org.eclipse.winery.repository/src/test/java/org/eclipse/winery/repository/PrefsTestEnabledGitBackedRepository.java b/winery/org.eclipse.winery.repository/src/test/java/org/eclipse/winery/repository/PrefsTestEnabledGitBackedRepository.java
new file mode 100644
index 0000000..fc702d8
--- /dev/null
+++ b/winery/org.eclipse.winery.repository/src/test/java/org/eclipse/winery/repository/PrefsTestEnabledGitBackedRepository.java
@@ -0,0 +1,30 @@
+/*******************************************************************************
+ * Copyright (c) 2012-2013 University of Stuttgart.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * and the Apache License 2.0 which both accompany this distribution,
+ * and are available at http://www.eclipse.org/legal/epl-v10.html
+ * and http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Contributors:
+ * Oliver Kopp - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.winery.repository;
+
+import java.io.IOException;
+
+import org.eclipse.winery.repository.backend.filebased.GitBasedRepository;
+
+public class PrefsTestEnabledGitBackedRepository extends PrefsTestEnabled {
+
+ public PrefsTestEnabledGitBackedRepository() throws IOException {
+ super(false);
+ // TODO: we should to a new clone of the repository
+ // currently, we rely on the right configuration of the preferences to use a file-based repository
+
+ // code similar to org.eclipse.winery.repository.Prefs.doRepositoryInitialization()
+ String repositoryLocation = this.properties.getProperty("repositoryPath");
+ this.repository = new GitBasedRepository(repositoryLocation);
+ }
+
+}
diff --git a/winery/org.eclipse.winery.repository/src/test/java/org/eclipse/winery/repository/PrefsTestEnabledUsingConfiguredRepository.java b/winery/org.eclipse.winery.repository/src/test/java/org/eclipse/winery/repository/PrefsTestEnabledUsingConfiguredRepository.java
new file mode 100644
index 0000000..0aea8ed
--- /dev/null
+++ b/winery/org.eclipse.winery.repository/src/test/java/org/eclipse/winery/repository/PrefsTestEnabledUsingConfiguredRepository.java
@@ -0,0 +1,28 @@
+/*******************************************************************************
+ * Copyright (c) 2012-2013 University of Stuttgart.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * and the Apache License 2.0 which both accompany this distribution,
+ * and are available at http://www.eclipse.org/legal/epl-v10.html
+ * and http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Contributors:
+ * Oliver Kopp - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.winery.repository;
+
+import java.io.IOException;
+
+/**
+ * Initializes the preferences with the repository given in winery.preferences
+ *
+ * FIXME: no test should use this one. Each test should configure the repository
+ * by itself.
+ */
+public class PrefsTestEnabledUsingConfiguredRepository extends PrefsTestEnabled {
+
+ public PrefsTestEnabledUsingConfiguredRepository() throws IOException {
+ super(true);
+ }
+
+}
diff --git a/winery/org.eclipse.winery.repository/src/test/java/org/eclipse/winery/repository/TestWithRepositoryConnection.java b/winery/org.eclipse.winery.repository/src/test/java/org/eclipse/winery/repository/TestWithRepositoryConnection.java
new file mode 100644
index 0000000..d2a2f88
--- /dev/null
+++ b/winery/org.eclipse.winery.repository/src/test/java/org/eclipse/winery/repository/TestWithRepositoryConnection.java
@@ -0,0 +1,27 @@
+/*******************************************************************************
+ * Copyright (c) 2012-2013 University of Stuttgart.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * and the Apache License 2.0 which both accompany this distribution,
+ * and are available at http://www.eclipse.org/legal/epl-v10.html
+ * and http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Contributors:
+ * Oliver Kopp - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.winery.repository;
+
+import java.io.IOException;
+
+import org.junit.BeforeClass;
+
+public abstract class TestWithRepositoryConnection {
+
+ @BeforeClass
+ public static void connectToProvider() throws IOException {
+ // Initialize preferences
+ // We do not need them, but constructing them has the side effect that Repository.INSTANCE is != null
+ new PrefsTestEnabledUsingConfiguredRepository();
+ }
+
+}
diff --git a/winery/org.eclipse.winery.repository/src/test/java/org/eclipse/winery/repository/UtilsTest.java b/winery/org.eclipse.winery.repository/src/test/java/org/eclipse/winery/repository/UtilsTest.java
new file mode 100644
index 0000000..02f04f9
--- /dev/null
+++ b/winery/org.eclipse.winery.repository/src/test/java/org/eclipse/winery/repository/UtilsTest.java
@@ -0,0 +1,26 @@
+/*******************************************************************************
+ * Copyright (c) 2012-2013 University of Stuttgart.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * and the Apache License 2.0 which both accompany this distribution,
+ * and are available at http://www.eclipse.org/legal/epl-v10.html
+ * and http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Contributors:
+ * Oliver Kopp - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.winery.repository;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class UtilsTest {
+
+ @Test
+ public void testCreateID() {
+ Assert.assertEquals("Frank_s_test", Utils.createXMLid("Frank's test").getDecoded());
+ Assert.assertEquals("MyNodeType", Utils.createXMLid("MyNodeType").getDecoded());
+ Assert.assertEquals("A_Node_Type", Utils.createXMLid("A Node Type").getDecoded());
+ }
+
+}
diff --git a/winery/org.eclipse.winery.repository/src/test/java/org/eclipse/winery/repository/export/TestToscaExporter.java b/winery/org.eclipse.winery.repository/src/test/java/org/eclipse/winery/repository/export/TestToscaExporter.java
new file mode 100644
index 0000000..5411cec
--- /dev/null
+++ b/winery/org.eclipse.winery.repository/src/test/java/org/eclipse/winery/repository/export/TestToscaExporter.java
@@ -0,0 +1,81 @@
+/*******************************************************************************
+ * Copyright (c) 2012-2013 University of Stuttgart.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * and the Apache License 2.0 which both accompany this distribution,
+ * and are available at http://www.eclipse.org/legal/epl-v10.html
+ * and http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Contributors:
+ * Oliver Kopp - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.winery.repository.export;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.StreamingOutput;
+import javax.xml.bind.JAXBException;
+
+import org.apache.commons.io.output.NullOutputStream;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.eclipse.winery.common.ids.definitions.ServiceTemplateId;
+import org.eclipse.winery.repository.PrefsTestEnabledGitBackedRepository;
+import org.eclipse.winery.repository.backend.Repository;
+import org.eclipse.winery.repository.backend.filebased.GitBasedRepository;
+
+public class TestToscaExporter {
+
+ //private static final TOSCAExportUtil toscaExporter = new TOSCAExportUtil();
+ private static final CSARExporter csarExporter = new CSARExporter();
+
+ private static final ServiceTemplateId serviceTemplateId = new ServiceTemplateId("http://www.example.com/tosca/ServiceTemplates/Moodle", "Moodle", false);
+
+
+ /**
+ * Quick hack as we currently don't have a dedicated test service template
+ */
+ @BeforeClass
+ public static void setServiceTemplateId() throws Exception {
+ // Initialize preferences
+ // We do not need them, but constructing them has the side effect that Repository.INSTANCE is != null
+ new PrefsTestEnabledGitBackedRepository();
+ }
+
+ @Before
+ public void setRevision() throws Exception {
+ ((GitBasedRepository) Repository.INSTANCE).setRevisionTo("97fa997b92965d8bc84e86274b0203f1db7495c5");
+ }
+
+ @Test
+ public void checkTOSCAExport() throws Exception {
+ @SuppressWarnings("unused")
+ StreamingOutput so = new StreamingOutput() {
+
+ @Override
+ public void write(OutputStream output) throws IOException, WebApplicationException {
+ TOSCAExportUtil exporter = new TOSCAExportUtil();
+ // we include everything related
+ Map<String, Object> conf = new HashMap<>();
+ try {
+ exporter.exportTOSCA(TestToscaExporter.serviceTemplateId, output, conf);
+ } catch (JAXBException e) {
+ throw new WebApplicationException(e);
+ }
+ }
+ };
+
+ // TODO: check output contained in SO
+ }
+
+ @Test
+ public void checkCSARExport() throws Exception {
+ NullOutputStream out = new NullOutputStream();
+ TestToscaExporter.csarExporter.writeCSAR(TestToscaExporter.serviceTemplateId, out);
+ }
+}
diff --git a/winery/org.eclipse.winery.repository/src/test/java/org/eclipse/winery/repository/importing/TestCSARImporter.java b/winery/org.eclipse.winery.repository/src/test/java/org/eclipse/winery/repository/importing/TestCSARImporter.java
new file mode 100644
index 0000000..f2778df
--- /dev/null
+++ b/winery/org.eclipse.winery.repository/src/test/java/org/eclipse/winery/repository/importing/TestCSARImporter.java
@@ -0,0 +1,48 @@
+/*******************************************************************************
+ * Copyright (c) 2012-2013,2015 University of Stuttgart.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * and the Apache License 2.0 which both accompany this distribution,
+ * and are available at http://www.eclipse.org/legal/epl-v10.html
+ * and http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Contributors:
+ * Oliver Kopp - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.winery.repository.importing;
+
+import java.nio.file.FileSystems;
+import java.nio.file.Path;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.winery.repository.PrefsTestEnabledUsingConfiguredRepository;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class TestCSARImporter {
+
+ /**
+ * Ensure that Repository.INSTANCE exists
+ */
+ @BeforeClass
+ public static void setupPrefs() throws Exception {
+ // Initialize preferences
+ // We do not need them directly, but constructing them has the side effect that Repository.INSTANCE is != null
+ new PrefsTestEnabledUsingConfiguredRepository();
+ }
+
+ /**
+ * Quick hack to test Moodle Import
+ *
+ * Currently, no CSARs are put into the test resources, we rely on local
+ * CSARs
+ */
+ @Test
+ public void testMoodleImport() throws Exception {
+ CSARImporter i = new CSARImporter();
+ Path p = FileSystems.getDefault().getPath("C:\\Users\\Oliver\\BTSync\\Projects\\OpenTOSCA\\MoodleInteropCSAR\\trunk");
+ List<String> errors = new ArrayList<String>();
+ i.importFromDir(p, errors, true, false);
+ }
+}
diff --git a/winery/org.eclipse.winery.repository/src/test/java/org/eclipse/winery/repository/resources/TestAbstractComponentInstanceResourceDefinitionsBacked.java b/winery/org.eclipse.winery.repository/src/test/java/org/eclipse/winery/repository/resources/TestAbstractComponentInstanceResourceDefinitionsBacked.java
new file mode 100644
index 0000000..1e65954
--- /dev/null
+++ b/winery/org.eclipse.winery.repository/src/test/java/org/eclipse/winery/repository/resources/TestAbstractComponentInstanceResourceDefinitionsBacked.java
@@ -0,0 +1,54 @@
+/*******************************************************************************
+ * Copyright (c) 2012-2013 University of Stuttgart.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * and the Apache License 2.0 which both accompany this distribution,
+ * and are available at http://www.eclipse.org/legal/epl-v10.html
+ * and http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Contributors:
+ * Oliver Kopp - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.winery.repository.resources;
+
+import java.io.IOException;
+
+import org.eclipse.winery.common.ids.XMLId;
+import org.eclipse.winery.common.ids.definitions.CapabilityTypeId;
+import org.eclipse.winery.repository.backend.MockXMLElement;
+import org.eclipse.winery.repository.backend.Repository;
+import org.eclipse.winery.repository.resources.entitytypes.capabilitytypes.CapabilityTypeResource;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class TestAbstractComponentInstanceResourceDefinitionsBacked extends TestResource {
+
+ private static final CapabilityTypeId id = new CapabilityTypeId(TestResource.NS, new XMLId("testCapabilityType", false));
+
+
+ @Test
+ public void testPlainPersist() throws IOException {
+ // ensure that no test object exists
+ Repository.INSTANCE.forceDelete(TestAbstractComponentInstanceResourceDefinitionsBacked.id);
+
+ CapabilityTypeResource res = new CapabilityTypeResource(TestAbstractComponentInstanceResourceDefinitionsBacked.id);
+ res.persist();
+ Assert.assertTrue("Element has to exist", Repository.INSTANCE.exists(TestAbstractComponentInstanceResourceDefinitionsBacked.id));
+ }
+
+ @Test
+ public void testPersistWithData() throws IOException {
+ // ensure that no test object exists
+ Repository.INSTANCE.forceDelete(TestAbstractComponentInstanceResourceDefinitionsBacked.id);
+
+ CapabilityTypeResource res = new CapabilityTypeResource(TestAbstractComponentInstanceResourceDefinitionsBacked.id);
+ res.getElement().getAny().add(new MockXMLElement());
+ res.persist();
+ Assert.assertTrue("Element has to exist", Repository.INSTANCE.exists(TestAbstractComponentInstanceResourceDefinitionsBacked.id));
+
+ // reload data
+ res = new CapabilityTypeResource(TestAbstractComponentInstanceResourceDefinitionsBacked.id);
+
+ Assert.assertEquals(1, res.getElement().getAny().size());
+ }
+}
diff --git a/winery/org.eclipse.winery.repository/src/test/java/org/eclipse/winery/repository/resources/TestResource.java b/winery/org.eclipse.winery.repository/src/test/java/org/eclipse/winery/repository/resources/TestResource.java
new file mode 100644
index 0000000..2841942
--- /dev/null
+++ b/winery/org.eclipse.winery.repository/src/test/java/org/eclipse/winery/repository/resources/TestResource.java
@@ -0,0 +1,22 @@
+/*******************************************************************************
+ * Copyright (c) 2012-2013 University of Stuttgart.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * and the Apache License 2.0 which both accompany this distribution,
+ * and are available at http://www.eclipse.org/legal/epl-v10.html
+ * and http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Contributors:
+ * Oliver Kopp - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.winery.repository.resources;
+
+import org.eclipse.winery.common.ids.Namespace;
+import org.eclipse.winery.repository.TestWithRepositoryConnection;
+
+public abstract class TestResource extends TestWithRepositoryConnection {
+
+ protected static final String TESTNS = "http://www.example.org/winery/test/resources";
+ protected static final Namespace NS = new Namespace(TestResource.TESTNS, false);
+
+}
diff --git a/winery/org.eclipse.winery.repository/src/test/java/org/eclipse/winery/repository/resources/entitytemplates/artifacttemplates/TestArtifactTemplateResource.java b/winery/org.eclipse.winery.repository/src/test/java/org/eclipse/winery/repository/resources/entitytemplates/artifacttemplates/TestArtifactTemplateResource.java
new file mode 100644
index 0000000..e7e3e5a
--- /dev/null
+++ b/winery/org.eclipse.winery.repository/src/test/java/org/eclipse/winery/repository/resources/entitytemplates/artifacttemplates/TestArtifactTemplateResource.java
@@ -0,0 +1,43 @@
+/*******************************************************************************
+ * Copyright (c) 2012-2013 University of Stuttgart.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * and the Apache License 2.0 which both accompany this distribution,
+ * and are available at http://www.eclipse.org/legal/epl-v10.html
+ * and http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Contributors:
+ * Oliver Kopp - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.winery.repository.resources.entitytemplates.artifacttemplates;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.eclipse.winery.common.ids.definitions.ArtifactTemplateId;
+import org.eclipse.winery.repository.PrefsTestEnabledGitBackedRepository;
+import org.eclipse.winery.repository.backend.Repository;
+import org.eclipse.winery.repository.backend.filebased.GitBasedRepository;
+import org.eclipse.winery.repository.resources.AbstractComponentsResource;
+
+public class TestArtifactTemplateResource {
+
+ @BeforeClass
+ public static void init() throws Exception {
+ // enable git-backed repository
+ new PrefsTestEnabledGitBackedRepository();
+ }
+
+ @Before
+ public void setRevision() throws Exception {
+ ((GitBasedRepository) Repository.INSTANCE).setRevisionTo("97fa997b92965d8bc84e86274b0203f1db7495c5");
+ }
+
+ @Test
+ public void countMatches() {
+ ArtifactTemplateId id = new ArtifactTemplateId("http%3A%2F%2Fdocs.oasis-open.org%2Ftosca%2Fns%2F2011%2F12%2FToscaSpecificTypes", "at-0cd9ab5d-6c2e-4fc2-9cb0-3fee1e431f9f", true);
+ ArtifactTemplateResource res = (ArtifactTemplateResource) AbstractComponentsResource.getComponentInstaceResource(id);
+ Assert.assertEquals(1, res.getReferenceCount());
+ }
+}
diff --git a/winery/org.eclipse.winery.repository/src/test/java/org/eclipse/winery/repository/resources/entitytypes/capabilitytypes/TestCapabilityTypeResource.java b/winery/org.eclipse.winery.repository/src/test/java/org/eclipse/winery/repository/resources/entitytypes/capabilitytypes/TestCapabilityTypeResource.java
new file mode 100644
index 0000000..098d59a
--- /dev/null
+++ b/winery/org.eclipse.winery.repository/src/test/java/org/eclipse/winery/repository/resources/entitytypes/capabilitytypes/TestCapabilityTypeResource.java
@@ -0,0 +1,53 @@
+/*******************************************************************************
+ * Copyright (c) 2012-2013 University of Stuttgart.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * and the Apache License 2.0 which both accompany this distribution,
+ * and are available at http://www.eclipse.org/legal/epl-v10.html
+ * and http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Contributors:
+ * Oliver Kopp - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.winery.repository.resources.entitytypes.capabilitytypes;
+
+import java.io.IOException;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.eclipse.winery.common.ids.Namespace;
+import org.eclipse.winery.common.ids.XMLId;
+import org.eclipse.winery.common.ids.definitions.CapabilityTypeId;
+import org.eclipse.winery.repository.PrefsTestEnabledGitBackedRepository;
+import org.eclipse.winery.repository.backend.Repository;
+import org.eclipse.winery.repository.backend.filebased.GitBasedRepository;
+import org.eclipse.winery.repository.resources.TestResource;
+
+public class TestCapabilityTypeResource extends TestResource {
+
+ private static final CapabilityTypeId id = new CapabilityTypeId(new Namespace("http://docs.oasis-open.org/tosca/ns/2011/12/ToscaBaseTypes", false), new XMLId("ContainerCapability", false));
+
+
+ @BeforeClass
+ public static void init() throws Exception {
+ // enable git-backed repository
+ new PrefsTestEnabledGitBackedRepository();
+ }
+
+ @Before
+ public void setRevision() throws Exception {
+ ((GitBasedRepository) Repository.INSTANCE).setRevisionTo("97fa997b92965d8bc84e86274b0203f1db7495c5");
+ }
+
+ @Test
+ public void getElementAsXMLString() throws IOException {
+ // ensure that no test object exists
+ Repository.INSTANCE.forceDelete(TestCapabilityTypeResource.id);
+
+ CapabilityTypeResource res = new CapabilityTypeResource(TestCapabilityTypeResource.id);
+ String s = res.getDefinitionsAsXMLString();
+ Assert.assertNotNull(s);
+ }
+}
diff --git a/winery/org.eclipse.winery.repository/src/test/java/org/eclipse/winery/repository/resources/entitytypes/nodetypes/reqandcapdefs/TestRequirementDefinitions.java b/winery/org.eclipse.winery.repository/src/test/java/org/eclipse/winery/repository/resources/entitytypes/nodetypes/reqandcapdefs/TestRequirementDefinitions.java
new file mode 100644
index 0000000..47ee3d0
--- /dev/null
+++ b/winery/org.eclipse.winery.repository/src/test/java/org/eclipse/winery/repository/resources/entitytypes/nodetypes/reqandcapdefs/TestRequirementDefinitions.java
@@ -0,0 +1,144 @@
+/*******************************************************************************
+ * Copyright (c) 2012-2013 University of Stuttgart.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * and the Apache License 2.0 which both accompany this distribution,
+ * and are available at http://www.eclipse.org/legal/epl-v10.html
+ * and http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Contributors:
+ * Oliver Kopp - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.winery.repository.resources.entitytypes.nodetypes.reqandcapdefs;
+
+import javax.ws.rs.core.MediaType;
+
+import org.hamcrest.Matchers;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.FixMethodOrder;
+import org.junit.Test;
+import org.junit.runners.MethodSorters;
+import org.eclipse.winery.repository.PrefsTestEnabledGitBackedRepository;
+import org.eclipse.winery.repository.backend.Repository;
+import org.eclipse.winery.repository.backend.filebased.GitBasedRepository;
+
+import com.jayway.restassured.RestAssured;
+import com.jayway.restassured.http.ContentType;
+import com.jayway.restassured.path.json.JsonPath;
+import com.jayway.restassured.response.Response;
+
+//@formatter:off
+
+/*
+ * import static com.jayway.restassured.RestAssured.*; import static
+ * com.jayway.restassured.matcher.RestAssuredMatchers.*; import static
+ * org.hamcrest.Matchers.*; import static
+ * com.jayway.restassured.path.json.JsonPath.*;
+ */
+
+
+/**
+ * REST-based testing of requirement definitions
+ *
+ * We use a fixed method sort order as we create resources in one test and work
+ * with them in the next step
+ */
+@FixMethodOrder(MethodSorters.NAME_ASCENDING)
+public class TestRequirementDefinitions {
+
+ @BeforeClass
+ public static void init() throws Exception {
+ // enable git-backed repository
+ new PrefsTestEnabledGitBackedRepository();
+
+ // we use a half-filled repository
+ ((GitBasedRepository) Repository.INSTANCE).setRevisionTo("97fa997b92965d8bc84e86274b0203f1db7495c5");
+
+ // we test on the Amazon EC2 node type
+ // could be any other node type without requirement definitions
+ //
+ // the following URI is already encoded (copied from the browser URL field)
+ RestAssured.urlEncodingEnabled = false;
+ RestAssured.basePath = "/org.eclipse.winery.repository/nodetypes/http%253A%252F%252Fwww.example.org%252Ftosca%252Fnodetypes/Amazon_EC2/requirementdefinitions";
+ }
+
+ @Test
+ public void test01_NoRequirementDefinitions() throws Exception {
+ RestAssured.given()
+ .header("Accept", MediaType.APPLICATION_JSON)
+ .expect()
+ .body(Matchers.equalTo("[]"))
+ .when()
+ .get("");
+ }
+
+ @Test
+ public void test02_CreateRequirementDefinition() throws Exception {
+ RestAssured.given()
+ .parameter("name", "test")
+ .expect()
+ .statusCode(204)
+ .when()
+ .post("/");
+ }
+
+ @Test
+ public void test03_NoConstraints() throws Exception {
+ RestAssured.given()
+ .header("Accept", MediaType.APPLICATION_JSON)
+ .expect()
+ .body(Matchers.equalTo("[]"))
+ .when()
+ .get("test/constraints/");
+ }
+
+ @Test
+ public void test04_CreateConstraint() throws Exception {
+ RestAssured.given()
+ .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\"/>")
+ .contentType(ContentType.XML)
+ .expect()
+ .statusCode(200)
+ .body(Matchers.notNullValue())
+ .when()
+ .post("test/constraints/");
+ }
+
+ @Test
+ public void test05_GetConstraint() throws Exception {
+ Response response = RestAssured
+ .given()
+ .header("Accept", MediaType.APPLICATION_JSON)
+ .expect()
+ .statusCode(200)
+ .when()
+ .get("test/constraints/");
+
+ // extract answer
+ JsonPath jsonPath = JsonPath.from(response.asString());
+
+ Assert.assertEquals("One id", jsonPath.getList("").size(), 1);
+
+ String id = jsonPath.getString("[0]");
+
+ // TODO: check content
+ RestAssured
+ .given()
+ .header("Accept", MediaType.TEXT_XML)
+ .expect()
+ .statusCode(200)
+ .when()
+ .get("test/constraints/{id}/", id);
+
+ // we also test the sub resource here
+ // otherwise we had to transport the id throught the code via a global variable
+ RestAssured
+ .expect()
+ .statusCode(200)
+ .body(Matchers.is("http://www.example.org/constrainttype"))
+ .when()
+ .get("test/constraints/{id}/type", id);
+ }
+
+}