assertNotNull(originalComponentBinding.bindings); assertEquals(2, originalComponentBinding.bindings.size()); assertTrue(hasBindingExpression(originalComponentBinding.bindings, "${mysql~restart_policy}")); assertTrue(hasBindingExpression(originalComponentBinding.bindings, "${_resource~mysql~address}:3306")); assertNotNull(resultComponentBinding.bindings); assertEquals(2, resultComponentBinding.bindings.size()); assertTrue(hasBindingExpression(resultComponentBinding.bindings, "${mysql~restart_policy}")); assertTrue(hasBindingExpression(resultComponentBinding.bindings, "${_resource~mysql~address}:3306"));
@Test public void testCompositeDescriptionContentServicesWithCharset() throws Throwable { Operation createOp = Operation .createPost(UriUtils.buildUri(host, CompositeDescriptionContentService.SELF_LINK)) .setContentType(MEDIA_TYPE_APPLICATION_YAML_WITH_CHARSET) .forceRemote() .setBody(template); AtomicReference<String> location = new AtomicReference<>(); verifyOperation(createOp, (o) -> { assertEquals("status code", Operation.STATUS_CODE_OK, o.getStatusCode()); location.set(o.getResponseHeader(Operation.LOCATION_HEADER)); assertNotNull("location header", location); }); verifyCompositeDescription(location.get()); }
private void verifyCompositeDescription(String location) throws Throwable { String selfLink = location.substring(location.lastIndexOf(UriUtils.URI_PATH_CHAR) + 1); assertNotNull("documentSelfLink", selfLink); URI uri = UriUtils.buildUri(host, location); URI expandUri = UriUtils.extendUriWithQuery(uri, UriUtils.URI_PARAM_ODATA_EXPAND, Boolean.TRUE.toString()); Operation getCompositeDescOp = Operation.createGet(expandUri); List<String> descriptionLinks = new ArrayList<>(); Consumer<Operation> verifier = (o) -> verifyTemplate.accept(o, descriptionLinks); verifyOperation(getCompositeDescOp, verifier); verifyDescriptions(descriptionLinks); verifyExport(selfLink); }
private void verifyExport(String selfLink) throws Throwable { URI uri = UriUtils.buildUri(host, CompositeDescriptionContentService.SELF_LINK); uri = UriUtils.extendUriWithQuery(uri, CompositeDescriptionContentService.SELF_LINK_PARAM_NAME, selfLink); verifyOperation(Operation.createGet(uri), (o) -> { String resultYaml = o.getBody(String.class); // Skip this validation for now. if (isKubernetesYaml(resultYaml)) { return; } // Can't compare the strings as the order of the components may not be the same. try { CompositeTemplate original = CompositeTemplateUtil.deserializeCompositeTemplate(template); CompositeTemplate result = CompositeTemplateUtil.deserializeCompositeTemplate(resultYaml); assertEquals(original.components.size(), result.components.size()); assertEquals(original.id, result.id); assertEquals(original.description, result.description); assertEquals(original.name, result.name); assertEquals(original.status, result.status); assertEquals(original.properties, result.properties); if (isBindingYaml(resultYaml)) { assertBindings(original, result, template, resultYaml); } } catch (IOException e) { fail(e.getMessage()); } }); }
@Test public void testValidateBadRequestOnImport() throws Throwable { this.host.testStart(1); this.host.send(validateBadRequestOnImportOperation((String) null, "body is required")); this.host.testWait(); this.host.testStart(1); this.host.send(validateBadRequestOnImportOperation("", "'yaml' cannot be empty")); this.host.testWait(); this.host.testStart(1); this.host.send(validateBadRequestOnImportOperation("abc", "Error processing YAML content: Cannot construct instance of `com.vmware.admiral.compute.content.compose.CommonDescriptionEntity` (although at least one Creator exists): no String-argument constructor/factory method to deserialize from String value ('abc')")); this.host.testWait(); this.host.testStart(1); this.host.send(validateBadRequestOnImportOperation(getContent("docker.redis.v1.yaml"), "Unknown YAML content type! Only Blueprint and Docker Compose v2 formats are supported.")); this.host.testWait(); this.host.testStart(1); this.host.send(validateBadRequestOnImportOperation(getContent("composite.bad.yaml"), "Cannot deserialize instance of `java.lang.String` out of START_OBJECT token\n at [Source: UNKNOWN; line: -1, column: -1] (through reference chain: com.vmware.admiral.compute.container.ContainerDescriptionService$CompositeTemplateContainerDescription[\"logConfig\"])")); this.host.testWait(); this.host.testStart(1); this.host.send(validateBadRequestOnImportOperation(new Date(), "Failed to deserialize CompositeTemplate serialized content!")); this.host.testWait(); this.host.testStart(1); this.host.send(validateBadRequestOnImportOperation( getContent("docker.invalid.network.yaml"), "Error processing Docker Compose v2 YAML content")); this.host.testWait(); }
@Test public void testCompositeDescriptionContentServices() throws Throwable { Operation createOp = Operation .createPost(UriUtils.buildUri(host, CompositeDescriptionContentService.SELF_LINK)) .setContentType(MEDIA_TYPE_APPLICATION_YAML) .forceRemote() .setBody(template); AtomicReference<String> location = new AtomicReference<>(); verifyOperation(createOp, (o) -> { assertEquals("status code", Operation.STATUS_CODE_OK, o.getStatusCode()); location.set(o.getResponseHeader(Operation.LOCATION_HEADER)); assertNotNull("location header", location); }); verifyCompositeDescription(location.get()); }
@Test public void testValidateNetworkAlias() throws Throwable { this.host.testStart(1); this.host.send( validateSuccessfulImportOperation(getContent("docker.network.alias.yaml"))); this.host.testWait(); }