Skip to content

fixed the test execution, added support for multiple yaml files #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/test/java/org/opentosca/container/client/CSARTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.opentosca.container.client;

import java.util.Map;

public class CSARTest {

private String name;
private Map<String, String> input;

public String getName(){
return name;
}
public void setName(String name){
this.name=name;
}

public Map<String,String> getInput(){
return input;
}
public void setInput(Map<String,String> input){
this.input=input;
}

}
38 changes: 0 additions & 38 deletions src/test/java/org/opentosca/container/client/ClientTests.java

This file was deleted.

159 changes: 64 additions & 95 deletions src/test/java/org/opentosca/container/client/ContainerClientTests.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
package org.opentosca.container.client;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Stream;
import java.net.Inet4Address;
import java.net.InetAddress;

import org.json.JSONObject;
import org.json.JSONArray;
import org.json.JSONTokener;
import io.swagger.client.model.ServiceTemplateInstanceDTO;
import org.junit.Assert;
import org.junit.Assume;
Expand All @@ -14,6 +26,7 @@
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.MethodSorters;
import org.junit.runners.Parameterized;
import org.opentosca.container.client.model.Application;
import org.opentosca.container.client.model.ApplicationInstance;
import org.opentosca.container.client.model.BoundaryDefinitionProperties;
Expand All @@ -24,21 +37,43 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import org.yaml.snakeyaml.TypeDescription;
import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.constructor.Constructor;

@RunWith(SpringRunner.class)
@SpringBootTest
@RunWith(Parameterized.class)
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class ContainerClientTests {

@Autowired
private ClientTests.Config config;
@Parameterized.Parameter(0)
public Testfiles config;

private ContainerClient client;

//retrieves the ipaddress which is defined in the dockerfile of the tests project
String ipAdress=System.getProperty("ipaddress");
String csarsPath="/var/opentosca/csars/";
//import all yaml configurations located in the resources folder
@Parameterized.Parameters
public static Iterable<Testfiles> data(){
File dir = new File("src/test/resources");
File[] directoryListing= dir.listFiles();
List<Testfiles> list = new ArrayList<>();
for(File child: directoryListing){
Yaml yaml = new Yaml(new Constructor(Testfiles.class));
try(InputStream in = Files.newInputStream(Paths.get(child.getAbsolutePath()))){
Testfiles tempconfig= yaml.load(in);
list.add(tempconfig);

}catch (Exception e){
e.printStackTrace();
}
}
return list;
}
@Before
public void before() {
this.client = ContainerClientBuilder.builder()
.withHostname(config.getHostname())
this.client = ContainerClientBuilder.builder()
.withHostname(ipAdress)
.build();
// Only run tests if OpenTOSCA ecosystem is up and running ;-)
try {
Expand All @@ -50,6 +85,7 @@ public void before() {

@Test
public void test_10_empty_responses() {

Assert.assertFalse(client.getApplication("test").isPresent());
for (Application application : client.getApplications()) {
client.removeApplication(application);
Expand All @@ -59,134 +95,67 @@ public void test_10_empty_responses() {

@Test
public void test_20_upload() {
for (ClientTests.Config.Test test : config.getTests()) {
for (CSARTest test : config.getTests()) {
System.out.println("Uploading CSAR-file "+test.getName());

Assert.assertFalse(client.getApplication(test.getName()).isPresent());
Path path = Paths.get(config.getPath(), test.getName());
Path path = Paths.get(csarsPath, test.getName());
Application application = client.uploadApplication(path);
Assert.assertEquals(test.getName(), application.getId());
System.out.println("Upload of CSAR-file "+test.getName()+" finished");

}
List<Application> applications = client.getApplications();

Assert.assertEquals(config.getTests().size(), applications.size());
}

@Test
public void test_21_get_boundary_definition_properties() {
for (ClientTests.Config.Test test : config.getTests()) {
Application application = client.getApplication(test.getName()).orElseThrow(IllegalStateException::new);
BoundaryDefinitionProperties properties = application.getBoundaryDefinitionProperties();
Assert.assertNotNull(properties);
Assert.assertNotNull(properties.getXMLFragment());
List<PropertyMapping> mappings = properties.getPropertyMappings();
Assert.assertNotNull(mappings);
mappings.forEach(mapping -> {
Assert.assertNotNull(mapping.getServiceTemplatePropertyRef());
Assert.assertNotNull(mapping.getTargetObjectRef());
Assert.assertNotNull(mapping.getTargetPropertyRef());
});
}
}

@Test
public void test_30_provision_application() {
for (ClientTests.Config.Test test : config.getTests()) {

for (CSARTest test : config.getTests()) {
System.out.println("Provisioning of "+test.getName());

Application application = client.getApplication(test.getName()).orElseThrow(IllegalStateException::new);
Assert.assertEquals(0, client.getApplicationInstances(application, ServiceTemplateInstanceDTO.StateEnum.CREATED).size());
int startSize = client.getApplicationInstances(application).size();
ApplicationInstance instance = client.provisionApplication(application, test.getInput());
System.out.println("Provisioning of "+test.getName()+ " finished");

Assert.assertNotNull(instance);
Assert.assertEquals(ServiceTemplateInstanceDTO.StateEnum.CREATED, instance.getState());
Assert.assertEquals(startSize + 1, client.getApplicationInstances(application).size());
Assert.assertEquals(1, client.getApplicationInstances(application, ServiceTemplateInstanceDTO.StateEnum.CREATED).size());
}
}

@Test
public void test_40_get_application_instances() {
for (ClientTests.Config.Test test : config.getTests()) {
Application application = client.getApplication(test.getName()).orElseThrow(IllegalStateException::new);
List<ApplicationInstance> applicationInstances = client.getApplicationInstances(application, ServiceTemplateInstanceDTO.StateEnum.CREATED);
Assert.assertEquals(1, applicationInstances.size());
for (ApplicationInstance instance : applicationInstances) {
Assert.assertEquals(PlanType.TERMINATION, instance.getTerminationPlan().getType());
List<Plan> managementPlans = instance.getManagementPlans();
for (Plan plan : managementPlans) {
Assert.assertEquals(PlanType.MANAGEMENT, plan.getType());
}
instance.getNodeInstances().forEach(i -> {
if (i.getTemplate().equals("DockerEngine")) {
Assert.assertEquals(i.getProperties().get("DockerEngineURL"), "tcp://dind:2375");
}
if (i.getTemplate().equals("MyTinyToDoDockerContainer")) {
Assert.assertEquals(i.getProperties().get("ContainerPort"), "80");
}
});
}
}
}

@Test
public void test_41_get_service_template_instance_properties() {
for (ClientTests.Config.Test test : config.getTests()) {
Application application = client.getApplication(test.getName()).orElseThrow(IllegalStateException::new);
List<ApplicationInstance> applicationInstances = client.getApplicationInstances(application, ServiceTemplateInstanceDTO.StateEnum.CREATED);
Assert.assertTrue(applicationInstances.size() > 0);
public void test_60_terminate_instance() {

for (ApplicationInstance instance : applicationInstances) {
Map<String,String> result = instance.getProperties();
Assert.assertNotNull(result);
Assert.assertTrue(result.size() > 0);
}
}
}
for (CSARTest test : config.getTests()) {
System.out.println("Terminating instance of "+test.getName());

@Test
public void test_45_execute_node_operation() {
for (ClientTests.Config.Test test : config.getTests()) {
Application application = client.getApplication(test.getName()).orElseThrow(IllegalStateException::new);
List<ApplicationInstance> applicationInstances = client.getApplicationInstances(application, ServiceTemplateInstanceDTO.StateEnum.CREATED);
Assert.assertEquals(1, applicationInstances.size());
for (ApplicationInstance instance : applicationInstances) {
instance.getNodeInstances().forEach(i -> {
if (i.getTemplate().equals("MyTinyToDoDockerContainer")) {
Map<String, String> input = new HashMap<>();
input.put("Script", "ls");
Map<String, String> result = client.executeNodeOperation(
instance, i,
"ContainerManagementInterface", "runScript",
input);
Assert.assertTrue(result.size() > 0);
}
});
}
}
}
System.out.println("Termination of "+test.getName()+ " finished");

@Test
public void test_50_get_buildplan_instances() {
for (ClientTests.Config.Test test : config.getTests()) {
Application application = client.getApplication(test.getName()).orElseThrow(IllegalStateException::new);
List<PlanInstance> buildPlanInstances = application.getBuildPlanInstances();
Assert.assertNotNull(buildPlanInstances);
buildPlanInstances.forEach(Assert::assertNotNull);
}
}

@Test
public void test_60_terminate_instance() {
for (ClientTests.Config.Test test : config.getTests()) {
Application application = client.getApplication(test.getName()).orElseThrow(IllegalStateException::new);
List<ApplicationInstance> applicationInstances = client.getApplicationInstances(application, ServiceTemplateInstanceDTO.StateEnum.CREATED);
Assert.assertEquals(1, applicationInstances.size());
for (ApplicationInstance instance : applicationInstances) {
Assert.assertTrue(client.terminateApplicationInstance(instance));
}
}

}

@Test
public void test_90_remove_application() {

for (Application application : client.getApplications()) {
System.out.println("Removing "+application.getName());
Assert.assertTrue(client.removeApplication(application));
System.out.println(application.getName()+" removed");
}
Assert.assertEquals(0, client.getApplications().size());
}
Expand Down
Loading