use of org.alien4cloud.tosca.model.CSARDependency in project alien4cloud by alien4cloud.
the class ServiceResourceServiceTest method testReportArchiveUsage.
@Test
public void testReportArchiveUsage() {
ServiceResource serviceResource = new ServiceResource();
serviceResource.setId("service1");
serviceResource.setName("service name 1");
serviceResource.setDependency(new CSARDependency("org.alien4cloud.archives:my-archive", "1.0.0-SNAPSHOT"));
alienDao.save(serviceResource);
ArchiveUsageRequestEvent archiveUsageRequestEvent = new ArchiveUsageRequestEvent(this, "org.alien4cloud.archives:my-archive", "1.0.0-SNAPSHOT");
serviceResourceService.reportArchiveUsage(archiveUsageRequestEvent);
Assert.assertEquals(1, archiveUsageRequestEvent.getUsages().size());
Assert.assertEquals("service1", archiveUsageRequestEvent.getUsages().get(0).getResourceId());
Assert.assertEquals("serviceresource", archiveUsageRequestEvent.getUsages().get(0).getResourceType());
Assert.assertEquals("service name 1", archiveUsageRequestEvent.getUsages().get(0).getResourceName());
archiveUsageRequestEvent = new ArchiveUsageRequestEvent(this, "org.alien4cloud.archives:other-archive", "1.0.0-SNAPSHOT");
serviceResourceService.reportArchiveUsage(archiveUsageRequestEvent);
Assert.assertEquals(0, archiveUsageRequestEvent.getUsages().size());
archiveUsageRequestEvent = new ArchiveUsageRequestEvent(this, "org.alien4cloud.archives:my-archive", "1.0.1-SNAPSHOT");
serviceResourceService.reportArchiveUsage(archiveUsageRequestEvent);
Assert.assertEquals(0, archiveUsageRequestEvent.getUsages().size());
}
use of org.alien4cloud.tosca.model.CSARDependency in project alien4cloud by alien4cloud.
the class CrudCSARSStepDefinition method The_csar_version_does_not_depend_on_csar_version.
@Then("^The CSAR \"([^\"]*)\" version \"([^\"]*)\" does not have a dependency to \"([^\"]*)\" version \"([^\"]*)\"$")
public void The_csar_version_does_not_depend_on_csar_version(String csarName, String csarVersion, String dependencyName, String dependencyVersion) throws Throwable {
String response = Context.getRestClientInstance().get("/rest/v1/csars/" + csarName + ":" + csarVersion);
CsarInfoDTO csar = JsonUtil.read(response, CsarInfoDTO.class).getData();
Assert.assertFalse(csar.getCsar().getDependencies().contains(new CSARDependency(dependencyName, dependencyVersion)));
}
use of org.alien4cloud.tosca.model.CSARDependency in project alien4cloud by alien4cloud.
the class CrudCSARSStepDefinition method I_add_a_dependency_with_name_version_to_the_CSAR_with_name_version.
@When("^I add a dependency with name \"([^\"]*)\" version \"([^\"]*)\" to the CSAR with name \"([^\"]*)\" version \"([^\"]*)\"$")
public void I_add_a_dependency_with_name_version_to_the_CSAR_with_name_version(String dependencyName, String dependencyVersion, String csarName, String csarVersion) throws Throwable {
CSARDependency dependency = new CSARDependency(dependencyName, dependencyVersion);
Context.getInstance().registerRestResponse(Context.getRestClientInstance().postJSon("/rest/v1/csars/" + csarName + ":" + csarVersion + "-SNAPSHOT" + "/dependencies", JsonUtil.toString(dependency)));
}
use of org.alien4cloud.tosca.model.CSARDependency in project alien4cloud by alien4cloud.
the class ToscaContextualAspect method findDependencies.
private Set<CSARDependency> findDependencies(Object[] args) {
for (Object arg : args) {
if (arg instanceof Topology) {
return ((Topology) arg).getDependencies();
}
if (arg instanceof Set) {
Set set = (Set) arg;
if (set.size() > 0 && set.iterator().next() instanceof CSARDependency) {
return (Set<CSARDependency>) arg;
}
}
if (arg instanceof AbstractToscaType) {
AbstractToscaType type = ((AbstractToscaType) arg);
Csar csar = csarRepositorySearchService.getArchive(type.getArchiveName(), type.getArchiveVersion());
if (csar == null) {
throw new NotFoundException("Unable to find dependencies from type as it's archive cannot be found in the repository.");
}
Set<CSARDependency> dependencies = csar.getDependencies() == null ? Sets.newHashSet() : csar.getDependencies();
dependencies.add(new CSARDependency(type.getArchiveName(), type.getArchiveVersion()));
return dependencies;
}
}
return Sets.<CSARDependency>newHashSet();
}
use of org.alien4cloud.tosca.model.CSARDependency in project alien4cloud by alien4cloud.
the class LocalRepositoryImpl method getElementInDependencies.
@Override
public <T extends AbstractToscaType> T getElementInDependencies(Class<T> elementClass, String elementId, Set<CSARDependency> dependencies) {
if (recursiveCall.get() == null) {
recursiveCall.set(true);
} else {
return null;
}
// ensure that dependencies are loaded in the ToscaContext
for (CSARDependency dependency : dependencies) {
// parse and register the archive from local repository.
parseAndRegister(dependency);
}
T element = ToscaContext.get(elementClass, elementId);
recursiveCall.remove();
return element;
}
Aggregations