...
 
.settings/
/classes/
/target/
.classpath
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>eu.DECIDEh2020.architect.appManager</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
This diff is collapsed.
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>de.decideh2020</groupId>
<artifactId>appManager</artifactId>
<version>0.0.1-SNAPSHOT</version>
<repositories>
<repository>
<id>jgit-repository</id>
<url>https://repo.eclipse.org/content/groups/releases/</url>
</repository>
</repositories>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<!-- Cloudpatterns dependency -->
<dependency>
<groupId>de.decideh2020</groupId>
<artifactId>cloudpatterns</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.eclipse.jgit</groupId>
<artifactId>org.eclipse.jgit</artifactId>
<version>4.9.0.201710071750-r</version>
</dependency>
<!-- Gson: Java to Json conversion -->
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.2</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.jena</groupId>
<artifactId>apache-jena-libs</artifactId>
<type>pom</type>
<version>3.4.0</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
/*
* Copyright (c) 2017 Fraunhofer FOKUS.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the
* Eclipse Public License version 2.0 which accompanies
* this distribution, and is available at
* https://opensource.org/licenses/EPL-2.0
*
* Contributors:
*
* Torben Jastrow (Fraunhofer FOKUS)
*
* **Initially developed in the context of DECIDE EU project www.DECIDE-h2020.eu */
package eu.DECIDEh2020.architect.appManager.models;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.UUID;
import org.apache.jena.rdf.model.Resource;
public class AppDescriptor {
private UUID id;
private String name, description, version;
private Boolean highTechnologicalRisk;
private LinkedList<Microservice> microservices;
private HashSet<Resource> projectNfrs;
private Object app_mcsla,containers[], virtual_machines[];
final public static String plugin_version ="0.2.2-alpha";
public AppDescriptor() {
id = UUID.randomUUID();
microservices = new LinkedList<Microservice>();
setDeploymentOrder();
this.projectNfrs = new HashSet<Resource>();
this.version = plugin_version;
}
/**
* @return the description
*/
public String getDescription() {
return description;
}
/**
* @param description the description to set
*/
public void setDescription(String description) {
this.description = description;
}
/**
* @return the version
*/
public String getVersion() {
return version;
}
/**
* @param version the version to set
*/
public void setVersion(String version) {
this.version = version;
}
/**
* @return the highTechnologicalRisk
*/
public Boolean getHighTechnologicalRisk() {
return highTechnologicalRisk;
}
/**
* @param highTechnologicalRisk the highTechnologicalRisk to set
*/
public void setHighTechnologicalRisk(Boolean highTechnologicalRisk) {
this.highTechnologicalRisk = highTechnologicalRisk;
}
/**
* @return the app_mcsla
*/
public Object getApp_mcsla() {
return app_mcsla;
}
/**
* @param app_mcsla the app_mcsla to set
*/
public void setApp_mcsla(Object app_mcsla) {
this.app_mcsla = app_mcsla;
}
/**
* @return the containers
*/
public Object[] getContainers() {
return containers;
}
/**
* @param containers the containers to set
*/
public void setContainers(Object[] containers) {
this.containers = containers;
}
/**
* @return the virtual_machines
*/
public Object[] getVirtual_machines() {
return virtual_machines;
}
/**
* @param virtual_machines the virtual_machines to set
*/
public void setVirtual_machines(Object[] virtual_machines) {
this.virtual_machines = virtual_machines;
}
/**
* @param id the id to set
*/
public void setId(UUID id) {
this.id = id;
}
public LinkedList<Microservice> changeIndex(int index, int plus) {
int size = microservices.size();
if (index+plus>=0&& index+plus<size) {
Microservice mscv = microservices.get(index);
microservices.remove(index);
microservices.add(index+plus, mscv);
}
setDeploymentOrder();
return microservices;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public void setDeploymentOrder(){
for (Microservice m: microservices) {
m.setDeployment_order(microservices.indexOf(m));
}
}
public LinkedList<Microservice> getMicroservices() {
return microservices;
}
public void setMicroservices(LinkedList<Microservice> microservices) {
this.microservices = microservices;
setDeploymentOrder();
}
public LinkedList<Microservice> addMicroservice(Microservice microservice) {
this.microservices.add(microservice);
setDeploymentOrder();
return this.microservices;
}
public LinkedList<Microservice> addMicroservices(int number){
for (int j = 0; j < number; j++) {
this.microservices.add(new Microservice());
}
setDeploymentOrder();
return this.microservices;
}
public LinkedList<Microservice> removeMicroservice(int index) {
this.microservices.remove(index);
setDeploymentOrder();
return this.microservices;
}
public LinkedList<Microservice> removeMicroservice(Microservice microservice) {
this.microservices.remove(microservice);
setDeploymentOrder();
return this.microservices;
}
public String getIDString() {
return id.toString();
}
/**
* @return the id
*/
public UUID getUID() {
return id;
}
public HashSet<Resource> getProjectNfrs() {
return projectNfrs;
}
public void setProjectNfrs(HashSet<Resource> projectNfrs) {
this.projectNfrs = projectNfrs;
}
public void addProjectNfr(Resource nfr) {
projectNfrs.add(nfr);
}
public void removeProjectNfr(Resource nfr) {
projectNfrs.remove(nfr);
}
}
/*
* Copyright (c) 2017 Fraunhofer FOKUS.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the
* Eclipse Public License version 2.0 which accompanies
* this distribution, and is available at
* https://opensource.org/licenses/EPL-2.0
*
* Contributors:
*
* Torben Jastrow (Fraunhofer FOKUS)
*
* **Initially developed in the context of DECIDE EU project www.DECIDE-h2020.eu */
package eu.DECIDEh2020.architect.appManager.models;
import java.net.URI;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.UUID;
import org.apache.jena.rdf.model.Resource;
public class Microservice {
private class InfrastructureRequirements{
private String disk_min, disk_max, ram;
/**
* @return the disk_min
*/
public String getDisk_min() {
return disk_min;
}
/**
* @param disk_min the disk_min to set
*/
public void setDisk_min(String disk_min) {
this.disk_min = disk_min;
}
/**
* @return the disk_max
*/
public String getDisk_max() {
return disk_max;
}
/**
* @param disk_max the disk_max to set
*/
public void setDisk_max(String disk_max) {
this.disk_max = disk_max;
}
/**
* @return the ram
*/
public String getRam() {
return ram;
}
/**
* @param ram the ram to set
*/
public void setRam(String ram) {
this.ram = ram;
}
}
private String ms_name, patterns[], programming_language ="", type, category, ms_repo ;
private HashSet<Resource> nfrs;
private UUID ms_uid;
private boolean stateless = false, publicIP =false;
private URI endpoint[], container_ref;
private int deployment_order;
private ArrayList<String> dependencies = new ArrayList<String>();
private InfrastructureRequirements infrastructure_requirements;
/**
* @return the programmingLanguage
*/
public String getProgrammingLanguage() {
return programming_language;
}
/**
* @param programmingLanguage the programmingLanguage to set
*/
public void setProgrammingLanguage(String programmingLanguage) {
this.programming_language = programmingLanguage;
}
/**
* @return the category
*/
public String getCategory() {
return category;
}
/**
* @param category the category to set
*/
public void setCategory(String category) {
this.category = category;
}
/**
* @return the endpoint
*/
public URI[] getEndpoint() {
return endpoint;
}
/**
* @param endpoint the endpoint to set
*/
public void setEndpoint(URI[] endpoint) {
this.endpoint = endpoint;
}
/**
* @return the container_ref
*/
public URI getContainer_ref() {
return container_ref;
}
/**
* @param container_ref the container_ref to set
*/
public void setContainer_ref(URI container_ref) {
this.container_ref = container_ref;
}
/**
* @return the deployment_order
*/
public int getDeployment_order() {
return deployment_order;
}
/**
* @param deployment_order the deployment_order to set
*/
public void setDeployment_order(int deployment_order) {
this.deployment_order = deployment_order;
}
/**
* @return the infrastructure_requirements
*/
public InfrastructureRequirements getInfrastructure_requirements() {
return infrastructure_requirements;
}
/**
* @param infrastructure_requirements the infrastructure_requirements to set
*/
public void setInfrastructure_requirements(InfrastructureRequirements infrastructure_requirements) {
this.infrastructure_requirements = infrastructure_requirements;
}
/**
* @return the repo
*/
public String getRepo() {
return ms_repo;
}
/**
* @param repo the repo to set
*/
public void setRepo(String repo) {
this.ms_repo = repo;
}
/**
* @return the id
*/
public UUID getUID() {
return ms_uid;
}
/**
* @param dependencies the dependencies to set
*/
public void setDependencies(ArrayList<String> dependencies) {
this.dependencies = dependencies;
}
public void addDependency(String dependency) {
this.dependencies.add(dependency);
}
public Microservice() {
this("Microservice ", UUID.randomUUID());
String uuid = this.getUIDstring().substring(0, 8);
this.setName("Microservice " + uuid);
}
public Microservice(String name) {
this(name, UUID.randomUUID());
}
public Microservice(UUID id) {
this("Microservice", id);
}
public Microservice(HashSet<Resource> nfrs) {
this("Microservice", nfrs);
}
public Microservice(String name, HashSet<Resource> nfrs) {
this(name, UUID.randomUUID(),nfrs );
}
public Microservice(String name, UUID id) {
this(name, id, new HashSet<Resource>() );
}
public Microservice(UUID id, HashSet<Resource> nfrs) {
this("Microservice", id,nfrs );
}
public Microservice(String name, UUID id, HashSet<Resource> nfrs) {
super();
this.ms_name = name;
this.ms_uid = id;
this.stateless=true;
this.nfrs = nfrs;
}
public String getUIDstring(){
return ms_uid.toString();
}
public String getName(){
return ms_name;
}
public void setName(String name) {
this.ms_name = name;
}
public HashSet<Resource> getNfrs() {
return nfrs;
}
public void setNfrs(HashSet<Resource> nfrs) {
this.nfrs = nfrs;
}
public String[] getPatterns() {
return patterns;
}
public void setPatterns(String[] patterns) {
this.patterns = patterns;
}
public String getLanguage() {
return programming_language;
}
public void setLanguage(String language) {
this.programming_language = language;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public boolean isStateless() {
return stateless;
}
public void setStateless(boolean stateless) {
this.stateless = stateless;
}
/**
* @return the dependencies
*/
public ArrayList<String> getDependencies() {
return dependencies;
}
}
/*
* Copyright (c) 2017 Fraunhofer FOKUS.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the
* Eclipse Public License version 2.0 which accompanies
* this distribution, and is available at
* https://opensource.org/licenses/EPL-2.0
*
* Contributors:
*
* Torben Jastrow (Fraunhofer FOKUS)
*
* **Initially developed in the context of DECIDE EU project www.DECIDE-h2020.eu */
package eu.DECIDEh2020.architect.appManager.persistence;
import java.io.File;
import java.io.IOException;
import java.util.Iterator;
import org.eclipse.jgit.api.AddCommand;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.PushCommand;
import org.eclipse.jgit.api.errors.CanceledException;
import org.eclipse.jgit.api.errors.ConcurrentRefUpdateException;
import org.eclipse.jgit.api.errors.DetachedHeadException;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.api.errors.InvalidConfigurationException;
import org.eclipse.jgit.api.errors.InvalidRemoteException;
import org.eclipse.jgit.api.errors.JGitInternalException;
import org.eclipse.jgit.api.errors.NoFilepatternException;
import org.eclipse.jgit.api.errors.NoHeadException;
import org.eclipse.jgit.api.errors.NoMessageException;
import org.eclipse.jgit.api.errors.RefNotFoundException;
import org.eclipse.jgit.api.errors.TransportException;
import org.eclipse.jgit.api.errors.WrongRepositoryStateException;
import org.eclipse.jgit.transport.CredentialsProvider;
import org.eclipse.jgit.transport.PushResult;
import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider;
public class GitHandler {
public static class Repository {
private String uri, path, host, user, password, name, port, protocol;
private boolean secureStorage = true, newRepo = true, localRepo=true;
public Repository(String uri, String path, String host, String user, String password, String port, String name, String protocol, boolean secureStorage) {
this.uri = uri;
this.path = path;
this.host = host;
this.user = user;
this.name = name;
this.port = port;
this.protocol = protocol;
this.password = password;
this.setSecureStorage(secureStorage);
}
public Repository() {
this.setSecureStorage(false);
}
/**
* @return the URI
*/
public String getURI() {
return uri;
}
/**
* @param URI
* the URI to set
*/
public void setURI(String uri) {
this.uri = uri;
}
/**
* @return the path
*/
public String getPath() {
return path;
}
/**
* @param path
* the path to set
*/
public void setPath(String path) {
this.path = path;
}
/**
* @return the host
*/
public String getHost() {
return host;
}
/**
* @param host
* the host to set
*/
public void setHost(String host) {
this.host = host;
}
/**
* @return the user
*/
public String getUser() {
return user;
}
/**
* @param user
* the user to set
*/
public void setUser(String user) {
this.user = user;
}
/**
* @return the password
*/
public String getPassword() {
return password;
}
/**
* @param password
* the password to set
*/
public void setPassword(String password) {
this.password = password;
}
/**
* @return the secureStorage
*/
public boolean isSecureStorage() {
return secureStorage;
}
/**
* @param secureStorage
* the secureStorage to set
*/
public void setSecureStorage(boolean secureStorage) {
this.secureStorage = secureStorage;
}
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @param name the name to set
*/
public void setName(String name) {
this.name = name;
}
/**
* @return the port
*/
public String getPort() {
return port;
}
/**
* @param port the port to set
*/
public void setPort(String port) {
this.port = port;
}
/**
* @return the protocol
*/
public String getProtocol() {
return protocol;
}
/**
* @param protocol the protocol to set
*/
public void setProtocol(String protocol) {
this.protocol = protocol;
}
/**
* @return the newRepo
*/
public boolean isNewRepo() {
return newRepo;
}
/**
* @param newRepo the newRepo to set
*/
public void setNewRepo(boolean newRepo) {
this.newRepo = newRepo;
}
/**
* @return the localRepo
*/
public boolean isLocalRepo() {
return localRepo;
}
/**
* @param localRepo the localRepo to set
*/
public void setLocalRepo(boolean localRepo) {
this.localRepo = localRepo;
}
}
private Repository repository;
private Git git;
private File directory;
private CredentialsProvider cp;
public GitHandler(Repository repository) {
this.repository=repository;
if(repository.getName()!=null && !repository.getName().isEmpty()
&& repository.getPassword()!=null && !repository.getPassword().isEmpty()) {
cp=new UsernamePasswordCredentialsProvider(repository.getName(), repository.getPassword());
}
}
public void cloneRepositoryTo(File dir) throws InvalidRemoteException, TransportException, GitAPIException {
Git git = Git.cloneRepository()
.setURI(repository.getURI())
.setCredentialsProvider(cp)
.setDirectory(dir)
.call();
setDirectory(git.getRepository().getDirectory());
git.close();
}
public void createRepositoryIn(File dir) throws IllegalStateException, GitAPIException {
git = Git.init().setDirectory(dir).call();
directory= git.getRepository().getDirectory();
}
public void cloneRepo() throws IOException, NoFilepatternException, GitAPIException {
Git.cloneRepository()
.setURI(repository.getURI())
.setDirectory(directory)
.call();
}
public void addToRepo() throws IOException, NoFilepatternException, GitAPIException {
AddCommand add = git.add();
add.addFilepattern(".").call();
}
public void commitToRepo(String message) throws IOException, NoHeadException,
NoMessageException, ConcurrentRefUpdateException,
JGitInternalException, WrongRepositoryStateException, GitAPIException {
git.commit().setMessage(message).call();
}
public void pushToRepo() throws IOException, JGitInternalException,
InvalidRemoteException, GitAPIException {
PushCommand pc = git.push();
pc.setCredentialsProvider(cp)
.setForce(true)
.setPushAll();
try {
Iterator<PushResult> it = pc.call().iterator();
if (it.hasNext()) {
System.out.println(it.next().toString());
}
} catch (InvalidRemoteException e) {
e.printStackTrace();
}
}
public void pullFromRepo() throws IOException, WrongRepositoryStateException,
InvalidConfigurationException, DetachedHeadException,
InvalidRemoteException, CanceledException, RefNotFoundException,
NoHeadException, GitAPIException {
git.pull().call();
}
public void setCredentials(String name,String password) {
cp=new UsernamePasswordCredentialsProvider(repository.getName(), repository.getPassword());
}
/**
* @return the repository
*/
public Repository getRepository() {
return repository;
}
/**
* @param repository the repository to set
*/
public void setRepository(Repository repository) {
this.repository = repository;
}
/**
* @return the directory
*/
public File getDirectory() {
return directory;
}
/**
* @param directory the directory to set
*/
public void setDirectory(File directory) {
this.directory = directory;
}
}
/*
* Copyright (c) 2017 Fraunhofer FOKUS.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the
* Eclipse Public License version 2.0 which accompanies
* this distribution, and is available at
* https://opensource.org/licenses/EPL-2.0
*
* Contributors:
*
* Torben Jastrow (Fraunhofer FOKUS)
*
* **Initially developed in the context of DECIDE EU project www.DECIDE-h2020.eu */
/**
*
*/
package eu.DECIDEh2020.architect.appManager.persistence;
import java.lang.reflect.Type;
import org.apache.jena.rdf.model.Resource;
import org.apache.jena.rdf.model.ResourceFactory;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.InstanceCreator;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import com.google.gson.JsonParser;
import com.google.gson.JsonPrimitive;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
import com.google.gson.JsonSyntaxException;
import eu.DECIDEh2020.architect.appManager.models.AppDescriptor;
import eu.DECIDEh2020.architect.cloudpatterns.Patterns;
/**
* @author tja
*
*/
public class JsonHandler {
public static class AppDescriptorWrapper {
// Old version means an older version than the one this class currently uses
private boolean oldVersion = false;
private String fileVersion = "";
private AppDescriptor appDescriptor = null;
public AppDescriptor getAppDescriptor() {
return appDescriptor;
}
public void setAppDescriptor(AppDescriptor appDescriptor) {
this.appDescriptor = appDescriptor;
}
public boolean isOldVersion() {
return oldVersion;
}
public void setOldVersion(boolean oldVersion) {
this.oldVersion = oldVersion;
}
public String getFileVersion() {
return fileVersion;
}
public void setFileVersion(String fileVersion) {
this.fileVersion = fileVersion;
}
}
private static class ResourceSerializer implements JsonSerializer<Resource> {
public JsonElement serialize(Resource src, Type typeOfSrc, JsonSerializationContext context) {
return new JsonPrimitive(src.toString());
}
}
private static class ResourceDeserializer implements JsonDeserializer<Resource> {
public Resource deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
throws JsonParseException {
return Patterns.createDefaultPatterns().getModel().createResource(json.getAsJsonPrimitive().getAsString());
}
}
private static class ResourceInstanceCreator implements InstanceCreator<Resource> {
public Resource createInstance(Type type) {
return ResourceFactory.createResource();
}
}
/**
* @param jsonString the String in JSON format to convert into an AppDescriptor Object
* @return AppDescriptorWrapper a wrapper Object containing the AppDescriptor and a Boolean value which might provide the reason for possible conversion errors by indicating the version of the AppDescriptor file.
* @throws JsonSyntaxException TODO
*/
public static AppDescriptorWrapper toAppDescriptor(String jsonString) throws JsonSyntaxException {
AppDescriptorWrapper app = new AppDescriptorWrapper();
Gson gson = new GsonBuilder().registerTypeAdapter(Resource.class, new ResourceInstanceCreator())
.registerTypeAdapter(Resource.class, new ResourceDeserializer()).create();
app.appDescriptor = gson.fromJson(jsonString, AppDescriptor.class);
JsonParser parser = new JsonParser();
JsonObject jsonObject = parser.parse(jsonString).getAsJsonObject();
if (jsonObject.has("version")) {
String version = parser.parse(jsonString).getAsJsonObject().get("version").getAsString();
if (!version.equals(AppDescriptor.plugin_version)) {
app.setOldVersion(true);
app.setFileVersion(version);
}
}
return app;
}
public static String fromAppDescriptor(AppDescriptor app) {
//create new gson with pretty printing activated and Serializer & deserializer for Resource Type
Gson gson = new GsonBuilder()
.setPrettyPrinting()
.registerTypeAdapter(Resource.class, new ResourceSerializer())
.registerTypeAdapter(Resource.class, new ResourceDeserializer())
.create();
//convert app descriptor object to json string
return gson.toJson(app);
}
}
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>eu.DECIDEh2020</groupId>
<artifactId>cloudpatterns</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.3</version>
</dependency>
<dependency>
<groupId>org.apache.jena</groupId>
<artifactId>apache-jena-libs</artifactId>
<type>pom</type>
<version>3.4.0</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.11</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
/*
* Copyright (c) 2017 Fraunhofer FOKUS.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the
* GNU AGPL v3 which accompanies
* this distribution, and is available at
* http://www.gnu.org/licenses/agpl.txt
*
* Contributors:
*
* Simon Dutkowski Fraunhofer FOKUS
*
* Initially developed in the context of DECIDE EU project www.DECIDE-h2020.eu
*/
package eu.DECIDEh2020.architect.patterns;
import eu.DECIDEh2020.architect.cloudpatterns.DECIDEPatterns;
import eu.DECIDEh2020.architect.cloudpatterns.DP;
import eu.DECIDEh2020.architect.cloudpatterns.Patterns;
import org.apache.jena.rdf.model.Resource;
import org.apache.jena.vocabulary.DCTerms;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import java.io.InputStream;
import java.util.Collections;
import java.util.List;
public class PatternsTest {
private Patterns patterns;
@BeforeTest
void initPatterns() {
patterns = Patterns.createDefaultPatterns();
assert patterns.getModel() != null : "Expected initial patterns model.";
}
@Test
void listPatterns() {
List<Resource> patternList = patterns.listPatterns();
assert patternList.size() == 13 : "Expected to get a list with 13 elements.";
}
@Test
void getPattern() {
Resource pattern = patterns.getPattern(DECIDEPatterns.BASE + "patterns/loose-coupling");
assert pattern != null : "Expected to get loose coupling pattern.";
assert pattern.getProperty(DCTerms.title).getString().equals("Loose Coupling") : "Expected 'Loose Coupling' in title";
}
@Test
void getIcon() {
Resource pattern = patterns.getPattern(DECIDEPatterns.BASE + "patterns/stateless-component");
assert pattern != null : "Expected stateless component pattern.";
Resource icon = pattern.getProperty(DP.icon).getResource();
assert icon != null : "Expected icon property";
InputStream stream = patterns.getIcon(icon);
assert stream != null : "Expected icon as input stream.";
}
@Test
void getSolution() {
Resource pattern = patterns.getPattern(DECIDEPatterns.BASE + "patterns/stateless-component");
assert pattern != null : "Expected stateless component pattern.";
assert !pattern.getProperty(DP.solution).getString().isEmpty(): "Expected non empty string.";
}
@Test
void testCategories() {
List<Resource> patternList = patterns.getPatternsByCategory(patterns.getModel().createResource(":dummy"));
assert patternList == null : "Expected null list";
patternList = patterns.getPatternsByCategory(DECIDEPatterns.fundamentalCategory);
assert patternList.size() == 7 : "Expected list of patterns with 7 elements.";
patternList = patterns.getPatternsByCategory(DECIDEPatterns.optimizationCategory);
assert patternList.size() == 5 : "Expected empty list of 5 patterns.";
patternList = patterns.getPatternsByCategory(DECIDEPatterns.developmentCategory);
assert patternList.size() == 2 : "Expected list of patterns with two elements.";
}
@Test
void listNFRs() {
List<Resource> patternList = patterns.listNFRs();
assert patternList.size() == 5 : "Expected to get a list with 5 elements.";
}
@Test
void testInference() {
List<Resource> patternList = patterns.inferPatterns(Collections.singletonList(DECIDEPatterns.scalability));
assert patternList.size() == 3 : "Expected to get a list with 3 elements.";
}
@Test
void testBadInference() {
List<Resource> patternList = patterns.inferBadPatterns(Collections.singletonList(DECIDEPatterns.scalability));
assert patternList.size() == 0 : "Expected to get a list with 0 elements.";
}
}
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>eu.DECIDEh2020</groupId>
<artifactId>cloudpatterns</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.3</version>
</dependency>
<dependency>
<groupId>org.apache.jena</groupId>
<artifactId>apache-jena-libs</artifactId>
<type>pom</type>
<version>3.4.0</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.11</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
@ModuleGen(groupPackage = "eu.DECIDEh2020.architect.cloudpatterns", name = "cloudpatternscompendium")
package eu.DECIDEh2020.architect.cloudpatterns.compendium.service;
import io.vertx.codegen.annotations.ModuleGen;
\ No newline at end of file
*.class
/target/
*/bin/
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>feature</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.pde.FeatureBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>