protected void assertExpectedFailureIncludesSampleId(Exception e) { String symbolicName = "sampleId"; String version = "0.1.0"; Asserts.expectedFailureContainsIgnoreCase(e, symbolicName + ":" + version); } protected void assertExpectedFailureSaysDifferentIsBad(Exception e) {
protected void assertExpectedFailureSaysDifferentIsBad(Exception e) { Asserts.expectedFailureContainsIgnoreCase(e, "cannot add", "different"); }
@Override protected void checkAddSameVersionFailsWhenIconIsDifferent(Exception e) { Asserts.expectedFailureContainsIgnoreCase(e, "cannot install a different bundle at a same non-snapshot version"); assertExpectedFailureIncludesSampleId(e); }
@Test public void testAddConfigFailure() throws Throwable { try { rebind(); Asserts.shouldHaveFailedPreviously(); } catch (Throwable e) { Asserts.expectedFailureContainsIgnoreCase(e, "minRam=4", "keyWithMapValue"); } }
@Test public void testLibraryMalformed() throws Exception { try { addCatalogItems( "brooklyn.catalog:", " id: simple-osgi-library", " version: \"1.0\"", " itemType: template", " libraries:", " - " + malformedJarUrl, " item:", " services:", " - type: " + BasicApplication.class.getName()); Asserts.shouldHaveFailedPreviously(); } catch (Exception e) { Asserts.expectedFailureContainsIgnoreCase(e, "opening zip"); } }
@Test public void testAddChildrenFailsWithoutServicesBlock() throws Exception { try { Entity child = makeAppAndAddChild(true, MutableMap.of("p.param1", "effector_param"), "blueprint_yaml: |", " type: "+BasicEntity.class.getName() ); // fine if implementation is improved to accept this format; // just change semantics of this test (and ensure comments on blueprint_yaml are changed!) Asserts.shouldHaveFailedPreviously("Didn't think we supported calls without 'services', but instantiation gave "+child); } catch (Exception e) { Asserts.expectedFailureContainsIgnoreCase(e, "basic", "error", "invalid"); } }
@Test public void testAddOddStringsAtRootIsError() { try { Jsonya.newInstance().add("a", 1, "b"); Asserts.shouldHaveFailedPreviously(); } catch (Exception e) { Asserts.expectedFailureContainsIgnoreCase(e, "odd"); } }
@Test public void testMaybeDisallowingNull() { Maybe<Object> m = Maybe.ofDisallowingNull(null); try { m.get(); Asserts.shouldHaveFailedPreviously(); } catch (Exception e) { Asserts.expectedFailureContainsIgnoreCase(e, "null"); } }
@Test public void testReferenceNonInstalledBundledByNameFails() { String nonExistentId = "none-existent-id"; String nonExistentVersion = "9.9.9"; try { addCatalogItems( "brooklyn.catalog:", " id: my.catalog.app.id.non_existing.ref", " version: " + TEST_VERSION, " itemType: entity", " libraries:", " - name: " + nonExistentId, " version: " + nonExistentVersion, " item:", " type: " + SIMPLE_ENTITY_TYPE); Asserts.shouldHaveFailedPreviously(); } catch (IllegalStateException e) { Asserts.expectedFailureContainsIgnoreCase(e, nonExistentId, nonExistentVersion, "no input stream", "no URL"); } }
@Test public void testUpdatingItemFailsIfDifferent() { TestResourceUnavailableException.throwIfResourceUnavailable(getClass(), OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_PATH); String id = "my.catalog.app.id.duplicate"; addCatalogOSGiEntity(id); try { addCatalogOSGiEntity(id, SIMPLE_ENTITY_TYPE, true); Asserts.shouldHaveFailedPreviously(); } catch (Exception e) { Asserts.expectedFailureContainsIgnoreCase(e, id, "already installed", "cannot install a different bundle at a same non-snapshot version"); } }
@Test public void testLibraryUrlDoesNotExist() throws Exception { String wrongUrl = "classpath:/path/does/not/exist/aefjaifjie3kdd.jar"; try { addCatalogItems( "brooklyn.catalog:", " id: simple-osgi-library", " version: \"1.0\"", " itemType: template", " libraries:", " - " + wrongUrl, " item:", " services:", " - type: " + BasicApplication.class.getName()); Asserts.shouldHaveFailedPreviously(); } catch (Exception e) { Asserts.expectedFailureContains(e, wrongUrl); Asserts.expectedFailureContainsIgnoreCase(e, "not found"); } }
@Test public void testJsonyaDeepSimpleFailure() { try { Jsonya.of(europeMap()).atExisting("euroope"); Asserts.shouldHaveFailedPreviously(); } catch (Exception e) { Asserts.expectedFailureContainsIgnoreCase(e, "euroope", "no", "found"); } }
Asserts.shouldHaveFailedPreviously(); } catch (Exception e) { Asserts.expectedFailureContainsIgnoreCase(e, "both name and version are required"); Asserts.shouldHaveFailedPreviously(); } catch (Exception e) { Asserts.expectedFailureContainsIgnoreCase(e, "both name and version are required");
public void testApplicationApiThrownError() throws Exception { try { ApplicationSummary summary = api.getApplicationApi().get("test-5678"); Asserts.shouldHaveFailedPreviously("got "+summary); } catch (Exception e) { Asserts.expectedFailureContainsIgnoreCase(e, "404", "not found"); } }
/** * Test that the name:version contained in the OSGi bundle will * override the values supplied in the YAML. */ @Test public void testFullBundleReferenceUrlMetaOverridesLocalNameVersion() { TestResourceUnavailableException.throwIfResourceUnavailable(getClass(), OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_PATH); String firstItemId = "my.catalog.app.id.register_bundle"; String nonExistentId = "non_existent_id"; String nonExistentVersion = "9.9.9"; try { addCatalogItems( "brooklyn.catalog:", " id: " + firstItemId, " version: " + TEST_VERSION, " itemType: entity", " libraries:", " - name: " + nonExistentId, " version: " + nonExistentVersion, " url: " + OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_URL, "", " item:", " type: " + SIMPLE_ENTITY_TYPE); Asserts.shouldHaveFailedPreviously(); } catch (IllegalStateException e) { Asserts.expectedFailureContainsIgnoreCase(e, nonExistentId, nonExistentVersion, "symbolic name mismatch", OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_NAME, OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_URL); } }
@Test public void startMethodFailsIfLocationsParameterHasMoreThanOneElement() throws Exception { DynamicCluster cluster = app.createAndManageChild(EntitySpec.create(DynamicCluster.class) .configure(DynamicCluster.MEMBER_SPEC, EntitySpec.create(TestEntity.class))); try { cluster.start(ImmutableList.of(loc, loc2)); Asserts.shouldHaveFailedPreviously(); } catch (Exception e) { Asserts.expectedFailureContainsIgnoreCase(e, "ambiguous"); } }
/** Does the class loader for the wrapped-more-entity type inherit more-entity's class loader? * Was tempting to say yes but the implementation is hard as we need to add API methods to find the * supertype (or supertypes). We might do that at which point we could change these semantics if we wished. * However there is also an argument that the instantiation engine determines where inherited loaders * behave transitively and where they don't, so we shouldn't have a blanket rule that you can always * see someone else's loaders just by extending them. In any case the "compelling use case" for * considering this (and noticing it, and adding comments to {@link RegisteredType#getLibraries()}) * is xml deserialization of entity specs in persisted state, and: * (a) there are other ways to do that, and * (b) we'd like to move away from that and use the same yaml-based instantiation engine used for initial construction. */ @Test public void testWrappedEntityClassLoaderDoesntHaveAncestorClassLoader() throws Exception { RegisteredType ci = installWrappedMoreEntity(); BrooklynClassLoadingContext clc = CatalogUtils.newClassLoadingContext(mgmt(), ci); try { clc.loadClass(BROOKLYN_TEST_MORE_ENTITIES_MORE_ENTITY); Asserts.shouldHaveFailedPreviously(); } catch (Exception e) { Asserts.expectedFailureContainsIgnoreCase(e, "unable to load", BROOKLYN_TEST_MORE_ENTITIES_MORE_ENTITY); } }
@Test public void testCircularReference() { BrooklynProperties properties = BrooklynProperties.Factory.newEmpty(); properties.put("brooklyn.location.named.bar", "named:bar"); mgmt = LocalManagementContextForTests.newInstance(properties); log.info("bar properties gave defined locations: "+mgmt.getLocationRegistry().getDefinedLocations(true)); try { mgmt.getLocationRegistry().getLocationSpec("bar").get(); Asserts.shouldHaveFailedPreviously("Circular reference gave a location"); } catch (IllegalStateException e) { Asserts.expectedFailureContainsIgnoreCase(e, "bar"); } }
@Test public void testFailsIfUsernameNull() throws Exception { try { feed = HttpFeed.builder() .entity(entity) .baseUrl(new URL("http://shouldNeverBeCalled.org")) .credentials(null, "Pa55w0rd") .poll(new HttpPollConfig<Integer>(SENSOR_INT) .period(100) .onSuccess(HttpValueFunctions.responseCode()) .onException(Functions.constant(-1))) .build(); Asserts.shouldHaveFailedPreviously(); } catch (IllegalArgumentException e) { Asserts.expectedFailureContainsIgnoreCase(e, "may not be null"); } }
@Test public void testAssertStrings() { Asserts.assertStringContains("hello", "hello", "he"); try { Asserts.assertStringContains("hello", "goodbye"); Asserts.shouldHaveFailedPreviously(); } catch (AssertionError e) { Asserts.expectedFailureContains(e, "hello", "goodbye"); Asserts.expectedFailureContainsIgnoreCase(e, "hello", "Goodbye"); } Asserts.assertStringContainsIgnoreCase("hello", "Hello"); try { Asserts.assertStringContains("hello", "Hello"); Asserts.shouldHaveFailedPreviously(); } catch (AssertionError e) { Asserts.expectedFailureContains(e, "hello", "Hello"); } Asserts.assertStringContainsAtLeastOne("hello", "hello", "goodbye"); try { Asserts.assertStringContainsAtLeastOne("hello", "Hello", "goodbye"); Asserts.shouldHaveFailedPreviously(); } catch (AssertionError e) { Asserts.expectedFailureContains(e, "hello", "Hello", "goodbye"); } Asserts.assertStringMatchesRegex("hello", "hello", "he.*", "he[ckl]+e*o"); try { Asserts.assertStringMatchesRegex("hello", "hello", "he"); Asserts.shouldHaveFailedPreviously(); } catch (AssertionError e) { Asserts.expectedFailureContains(e, "hello", "matchesRegex(he)"); } }