Skip to content

Commit

Permalink
the rest of the tosca tests now fixed
Browse files Browse the repository at this point in the history
note these need e72175d4b0746cd640740a5cf2c48d1d964731fe in A4C (Cloudsoft branch)
  • Loading branch information
ahgittin committed Dec 12, 2019
1 parent 7d8cac9 commit a64e733
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -322,25 +322,20 @@ private Optional<DeploymentArtifact> getArtifact(String nodeId, Alien4CloudAppli
return Optional.fromNullable(getArtifactsMap(nodeId, toscaApplication).get().get(artifactId));
}

private static final List<String> validInterfaceNames = ImmutableList.of("tosca.interfaces.node.lifecycle.Standard", "Standard", "standard");
private Map<String, Operation> getStandardInterfaceOperationsMap(String nodeId, Alien4CloudApplication toscaApplication) {
Map<String, Operation> operations = MutableMap.of();
NodeTemplate nodeTemplate = toscaApplication.getNodeTemplate(nodeId);
// or could getIndexedNodeTemplate(nodeId, toscaApplication) -- but above seems easier

// IndexedArtifactToscaElement indexedNodeTemplate = getIndexedNodeTemplate(nodeId, toscaApplication);
List<String> validInterfaceNames = ImmutableList.of("tosca.interfaces.node.lifecycle.Standard", "Standard", "standard");
// operations.putAll(getInterfaceOperationsMap(indexedNodeTemplate, validInterfaceNames));

// returns from the type not the node
Optional<Interface> optionalNodeTemplateInterface = NodeTemplates.findInterfaceOfNodeTemplate(
nodeTemplate.getInterfaces(), validInterfaceNames);

if (optionalNodeTemplateInterface.isPresent()) {
// merge is now done at build time (though possibly that's not ideal?)
// operations.putAll(optionalNodeTemplateInterface.get().getOperations());
// merge is now done at build time so we no longer need to look at node types
return optionalNodeTemplateInterface.get().getOperations();
}
// return empty default
return operations;

return MutableMap.of();
}

private Map<String, Operation> getConfigureInterfaceOperationsMap(Alien4CloudApplication toscaApplication, ToscaApplication.Relationship relationship) {
Expand Down Expand Up @@ -567,7 +562,7 @@ public Optional<Path> getArtifactPath(String nodeId, Alien4CloudApplication tosc
DeploymentArtifact artifact = optionalArtifact.get();
Optional<Path> csarPath = getCsarPath(artifact);
if (!csarPath.isPresent()) {
LOG.warn("CSAR " + artifactId + ":" + artifact.getArchiveVersion() + " does not exist");
LOG.warn("CSAR " + artifact.getArchiveName() + ":" + artifact.getArchiveVersion() + " for artifact "+artifactId+" does not exist");
return Optional.absent();
} else {
return Optional.of(Paths.get(csarPath.get().getParent().toAbsolutePath().toString(), "expanded", artifact.getArtifactRef()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,25 @@
import static org.mockito.Mockito.when;
import static org.testng.Assert.assertEquals;

import java.nio.file.Paths;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;

import org.apache.brooklyn.api.entity.EntitySpec;
import org.apache.brooklyn.camp.brooklyn.spi.dsl.methods.BrooklynDslCommon;
import org.apache.brooklyn.core.test.entity.TestEntity;
import org.apache.brooklyn.entity.software.base.SoftwareProcess;
import org.apache.brooklyn.test.Asserts;
import org.mockito.ArgumentMatchers;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

import com.google.common.base.Optional;
import com.google.common.collect.ImmutableMap;

import alien4cloud.component.repository.exception.CSARVersionNotFoundException;
Expand All @@ -30,6 +35,8 @@

public class RuntimeEnvironmentModifierSpecTest extends Alien4CloudToscaTest {

private static final Logger log = LoggerFactory.getLogger(RuntimeEnvironmentModifierSpecTest.class);

@Mock
private ToscaFacade alien4CloudFacade;
@Mock
Expand All @@ -48,6 +55,10 @@ public void initMocks(){
MockitoAnnotations.initMocks(this);
}

private static String escapeLiteralForRegex(String in) {
return in.replaceAll("[-\\[\\]{}()*+?.,\\\\\\\\^$|#\\s]", "\\\\$0");
}

@Test
public void testArtifactLocationsAreConfiguredAsShellVariables() throws CSARVersionNotFoundException {
final String artifactName = "artifactName";
Expand All @@ -61,19 +72,18 @@ public void testArtifactLocationsAreConfiguredAsShellVariables() throws CSARVers
Map<String, DeploymentArtifact> artifacts = ImmutableMap.of(artifactKey, artifact);

when(alien4CloudFacade.getArtifacts(anyString(), any(ToscaApplication.class))).thenReturn(artifacts.keySet());
when(alien4CloudFacade.getArtifactPath(anyString(), any(ToscaApplication.class), anyString())).thenReturn(Optional.of(Paths.get("/tmp")));
when(alien4CloudFacade.getArtifactRef(anyString(), any(ToscaApplication.class), ArgumentMatchers.eq(artifactKey))).thenReturn("http://foo");

//when(alien4CloudFacade.getArtifactPath(anyString(), any(ToscaApplication.class), anyString())).thenReturn(Optional.of(Paths.get("/tmp")));

EntitySpec<TestEntity> spec = EntitySpec.create(TestEntity.class);
RuntimeEnvironmentModifier modifier = new RuntimeEnvironmentModifier(mgmt, alien4CloudFacade);
modifier.apply(spec, "", toscaApplication);
String actual = spec.getConfig().get(SoftwareProcess.SHELL_ENVIRONMENT.subKey(artifactKey)).toString();
String expected = BrooklynDslCommon.formatString("%s/%s/%s", BrooklynDslCommon.attributeWhenReady("install.dir"),"RANDOM", artifactKey).toString();
String[] actualParts = actual.split("install.dir");
String[] expectedParts = expected.split("install.dir");
assertEquals(actualParts.length, expectedParts.length);
assertEquals(actualParts[0], expectedParts[0]);
// remove the random string for comparison, since we can't seed the Random object
assertEquals(actualParts[1].substring(11), expectedParts[1].substring(11), "full-actual="+actual+"; full-expected="+expected);

Asserts.assertStringMatchesRegex(
spec.getConfig().get(SoftwareProcess.SHELL_ENVIRONMENT.subKey(artifactKey)).toString(),
escapeLiteralForRegex(BrooklynDslCommon.formatString("%s/%s/%s", BrooklynDslCommon.attributeWhenReady("install.dir"), "__ANYTHING__", artifactKey).toString())
.replace("__ANYTHING__", ".*"));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,7 @@ topology_template:
configs:
implementation: configs
type: tosca.artifacts.File
description: configs
description: configs
# added to explicitly specify since it might be coming from imports
archive_name: mysql-type
archive_version: 2.0.0-SNAPSHOT

0 comments on commit a64e733

Please sign in to comment.