You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by sj...@apache.org on 2016/04/07 13:14:11 UTC
[5/9] brooklyn-server git commit: Remove jersey compatibility
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/3be4fe11/rest/rest-server-jersey/src/test/java/org/apache/brooklyn/rest/domain/ApiErrorTest.java
----------------------------------------------------------------------
diff --git a/rest/rest-server-jersey/src/test/java/org/apache/brooklyn/rest/domain/ApiErrorTest.java b/rest/rest-server-jersey/src/test/java/org/apache/brooklyn/rest/domain/ApiErrorTest.java
deleted file mode 100644
index f73bd30..0000000
--- a/rest/rest-server-jersey/src/test/java/org/apache/brooklyn/rest/domain/ApiErrorTest.java
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.brooklyn.rest.domain;
-
-import static org.apache.brooklyn.rest.util.RestApiTestUtils.asJson;
-import static org.apache.brooklyn.rest.util.RestApiTestUtils.fromJson;
-import static org.apache.brooklyn.rest.util.RestApiTestUtils.jsonFixture;
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertFalse;
-
-import java.io.IOException;
-import java.net.URI;
-
-import org.testng.annotations.Test;
-import org.testng.util.Strings;
-
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.ImmutableSet;
-
-public class ApiErrorTest extends AbstractDomainTest {
-
- @Override
- protected String getPath() {
- return "fixtures/api-error-basic.json";
- }
-
- @Override
- protected Object getDomainObject() {
- return ApiError.builder()
- .message("explanatory message")
- .details("accompanying details")
- .build();
- }
-
- @Test
- public void testSerializeApiErrorFromThrowable() throws IOException {
- Exception e = new Exception("error");
- e.setStackTrace(Thread.currentThread().getStackTrace());
-
- ApiError error = ApiError.builderFromThrowable(e).build();
- ApiError deserialised = fromJson(asJson(error), ApiError.class);
-
- assertFalse(Strings.isNullOrEmpty(deserialised.getDetails()), "Expected details to contain exception stack trace");
- assertEquals(deserialised, error);
- }
-
- @Test
- public void testSerializeApiErrorWithoutDetails() throws IOException {
- ApiError error = ApiError.builder()
- .message("explanatory message")
- .build();
- assertEquals(asJson(error), jsonFixture("fixtures/api-error-no-details.json"));
- }
-
-}
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/3be4fe11/rest/rest-server-jersey/src/test/java/org/apache/brooklyn/rest/domain/ApplicationSpecTest.java
----------------------------------------------------------------------
diff --git a/rest/rest-server-jersey/src/test/java/org/apache/brooklyn/rest/domain/ApplicationSpecTest.java b/rest/rest-server-jersey/src/test/java/org/apache/brooklyn/rest/domain/ApplicationSpecTest.java
deleted file mode 100644
index b2690d6..0000000
--- a/rest/rest-server-jersey/src/test/java/org/apache/brooklyn/rest/domain/ApplicationSpecTest.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.brooklyn.rest.domain;
-
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.ImmutableSet;
-
-public class ApplicationSpecTest extends AbstractDomainTest {
-
- @Override
- protected String getPath() {
- return "fixtures/application-spec.json";
- }
-
- @Override
- protected Object getDomainObject() {
- EntitySpec entitySpec = new EntitySpec("Vanilla Java App", "org.apache.brooklyn.entity.java.VanillaJavaApp",
- ImmutableMap.of("initialSize", "1", "creationScriptUrl", "http://my.brooklyn.io/storage/foo.sql"));
- return ApplicationSpec.builder().name("myapp")
- .entities(ImmutableSet.of(entitySpec)).locations(ImmutableSet.of("/v1/locations/1"))
- .build();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/3be4fe11/rest/rest-server-jersey/src/test/java/org/apache/brooklyn/rest/domain/ApplicationTest.java
----------------------------------------------------------------------
diff --git a/rest/rest-server-jersey/src/test/java/org/apache/brooklyn/rest/domain/ApplicationTest.java b/rest/rest-server-jersey/src/test/java/org/apache/brooklyn/rest/domain/ApplicationTest.java
deleted file mode 100644
index 8708fb1..0000000
--- a/rest/rest-server-jersey/src/test/java/org/apache/brooklyn/rest/domain/ApplicationTest.java
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.brooklyn.rest.domain;
-
-import static org.apache.brooklyn.rest.util.RestApiTestUtils.asJson;
-import static org.apache.brooklyn.rest.util.RestApiTestUtils.fromJson;
-import static org.apache.brooklyn.rest.util.RestApiTestUtils.jsonFixture;
-import static org.testng.Assert.assertEquals;
-
-import java.io.IOException;
-import java.net.URI;
-import java.util.Map;
-
-import org.apache.brooklyn.api.mgmt.ManagementContext;
-import org.apache.brooklyn.core.entity.Entities;
-import org.apache.brooklyn.core.test.entity.LocalManagementContextForTests;
-import org.apache.brooklyn.core.test.entity.TestApplication;
-import org.apache.brooklyn.test.Asserts;
-import org.testng.annotations.Test;
-
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.ImmutableSet;
-
-public class ApplicationTest {
-
- final EntitySpec entitySpec = new EntitySpec("Vanilla Java App", "org.apache.brooklyn.entity.java.VanillaJavaApp",
- ImmutableMap.of(
- "initialSize", "1",
- "creationScriptUrl", "http://my.brooklyn.io/storage/foo.sql"));
-
- final ApplicationSpec applicationSpec = ApplicationSpec.builder().name("myapp")
- .entities(ImmutableSet.of(entitySpec))
- .locations(ImmutableSet.of("/v1/locations/1"))
- .build();
-
- final Map<String, URI> links = ImmutableMap.of(
- "self", URI.create("/v1/applications/" + applicationSpec.getName()),
- "entities", URI.create("fixtures/entity-summary-list.json"));
- final ApplicationSummary application = new ApplicationSummary("myapp_id", applicationSpec, Status.STARTING, links);
-
- @SuppressWarnings("serial")
- @Test
- public void testSerializeToJSON() throws IOException {
- assertEquals(asJson(application), jsonFixture("fixtures/application.json"));
- }
-
- @Test
- public void testDeserializeFromJSON() throws IOException {
- assertEquals(fromJson(jsonFixture("fixtures/application.json"),
- ApplicationSummary.class), application);
- }
-
- @Test
- public void testTransitionToRunning() {
- ApplicationSummary running = application.transitionTo(Status.RUNNING);
- assertEquals(running.getStatus(), Status.RUNNING);
- }
-
- @Test
- public void testAppInAppTest() throws IOException {
- ManagementContext mgmt = LocalManagementContextForTests.newInstance();
- try {
- TestApplication app = mgmt.getEntityManager().createEntity(org.apache.brooklyn.api.entity.EntitySpec.create(TestApplication.class));
- app.addChild(org.apache.brooklyn.api.entity.EntitySpec.create(TestApplication.class));
- Asserts.assertEqualsIgnoringOrder(mgmt.getApplications(), ImmutableList.of(app));
- } finally {
- Entities.destroyAll(mgmt);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/3be4fe11/rest/rest-server-jersey/src/test/java/org/apache/brooklyn/rest/domain/EffectorSummaryTest.java
----------------------------------------------------------------------
diff --git a/rest/rest-server-jersey/src/test/java/org/apache/brooklyn/rest/domain/EffectorSummaryTest.java b/rest/rest-server-jersey/src/test/java/org/apache/brooklyn/rest/domain/EffectorSummaryTest.java
deleted file mode 100644
index 71cb64d..0000000
--- a/rest/rest-server-jersey/src/test/java/org/apache/brooklyn/rest/domain/EffectorSummaryTest.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.brooklyn.rest.domain;
-
-import java.net.URI;
-
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.ImmutableSet;
-
-public class EffectorSummaryTest extends AbstractDomainTest {
-
- @Override
- protected String getPath() {
- return "fixtures/effector-summary.json";
- }
-
- @Override
- protected Object getDomainObject() {
- return new EffectorSummary(
- "stop",
- "void",
- ImmutableSet.<EffectorSummary.ParameterSummary<?>>of(),
- "Effector description",
- ImmutableMap.of(
- "self", URI.create("/v1/applications/redis-app/entities/redis-ent/effectors/stop")));
- }
-
-}
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/3be4fe11/rest/rest-server-jersey/src/test/java/org/apache/brooklyn/rest/domain/EntitySpecTest.java
----------------------------------------------------------------------
diff --git a/rest/rest-server-jersey/src/test/java/org/apache/brooklyn/rest/domain/EntitySpecTest.java b/rest/rest-server-jersey/src/test/java/org/apache/brooklyn/rest/domain/EntitySpecTest.java
deleted file mode 100644
index 1beb078..0000000
--- a/rest/rest-server-jersey/src/test/java/org/apache/brooklyn/rest/domain/EntitySpecTest.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.brooklyn.rest.domain;
-
-import static org.apache.brooklyn.rest.util.RestApiTestUtils.fromJson;
-import static org.apache.brooklyn.rest.util.RestApiTestUtils.jsonFixture;
-import static org.testng.Assert.assertEquals;
-
-import java.io.IOException;
-
-import org.testng.annotations.Test;
-
-public class EntitySpecTest extends AbstractDomainTest {
-
- @Override
- protected String getPath() {
- return "fixtures/entity.json";
- }
-
- @Override
- protected Object getDomainObject() {
- EntitySpec entitySpec = new EntitySpec("Vanilla Java App", "org.apache.brooklyn.entity.java.VanillaJavaApp");
- return new EntitySpec[] { entitySpec };
- }
-
- @Test
- public void testDeserializeFromJSONOnlyWithType() throws IOException {
- EntitySpec actual = fromJson(jsonFixture("fixtures/entity-only-type.json"), EntitySpec.class);
- assertEquals(actual.getType(), "org.apache.brooklyn.entity.java.VanillaJavaApp");
- assertEquals(actual.getConfig().size(), 0);
- }
-}
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/3be4fe11/rest/rest-server-jersey/src/test/java/org/apache/brooklyn/rest/domain/EntitySummaryTest.java
----------------------------------------------------------------------
diff --git a/rest/rest-server-jersey/src/test/java/org/apache/brooklyn/rest/domain/EntitySummaryTest.java b/rest/rest-server-jersey/src/test/java/org/apache/brooklyn/rest/domain/EntitySummaryTest.java
deleted file mode 100644
index 2d39cc9..0000000
--- a/rest/rest-server-jersey/src/test/java/org/apache/brooklyn/rest/domain/EntitySummaryTest.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.brooklyn.rest.domain;
-
-import java.net.URI;
-import java.util.Map;
-
-import com.google.common.collect.Maps;
-
-public class EntitySummaryTest extends AbstractDomainTest {
-
- @Override
- protected String getPath() {
- return "fixtures/entity-summary.json";
- }
-
- @Override
- protected Object getDomainObject() {
- Map<String, URI> links = Maps.newLinkedHashMap();
- links.put("self", URI.create("/v1/applications/tesr/entities/zQsqdXzi"));
- links.put("catalog", URI.create("/v1/catalog/entities/org.apache.brooklyn.entity.webapp.tomcat.TomcatServer"));
- links.put("application", URI.create("/v1/applications/tesr"));
- links.put("children", URI.create("/v1/applications/tesr/entities/zQsqdXzi/children"));
- links.put("effectors", URI.create("fixtures/effector-summary-list.json"));
- links.put("sensors", URI.create("fixtures/sensor-summary-list.json"));
- links.put("activities", URI.create("fixtures/task-summary-list.json"));
-
- return new EntitySummary("zQsqdXzi", "MyTomcat",
- "org.apache.brooklyn.entity.webapp.tomcat.TomcatServer", null, links);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/3be4fe11/rest/rest-server-jersey/src/test/java/org/apache/brooklyn/rest/domain/LocationSpecTest.java
----------------------------------------------------------------------
diff --git a/rest/rest-server-jersey/src/test/java/org/apache/brooklyn/rest/domain/LocationSpecTest.java b/rest/rest-server-jersey/src/test/java/org/apache/brooklyn/rest/domain/LocationSpecTest.java
deleted file mode 100644
index 0e653c5..0000000
--- a/rest/rest-server-jersey/src/test/java/org/apache/brooklyn/rest/domain/LocationSpecTest.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.brooklyn.rest.domain;
-
-import static org.apache.brooklyn.rest.util.RestApiTestUtils.asJson;
-import static org.apache.brooklyn.rest.util.RestApiTestUtils.fromJson;
-import static org.apache.brooklyn.rest.util.RestApiTestUtils.jsonFixture;
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertNull;
-
-import java.io.IOException;
-
-import org.testng.annotations.Test;
-
-@Deprecated
-public class LocationSpecTest {
-
- // TODO when removing the deprecated class this tests, change the tests here to point at LocationSummary
-
- final LocationSpec locationSpec = LocationSpec.localhost();
-
- @Test
- public void testSerializeToJSON() throws IOException {
- assertEquals(asJson(locationSpec), jsonFixture("fixtures/location.json"));
- }
-
- @Test
- public void testDeserializeFromJSON() throws IOException {
- assertEquals(fromJson(jsonFixture("fixtures/location.json"), LocationSpec.class), locationSpec);
- }
-
- @Test
- public void testDeserializeFromJSONWithNoCredential() throws IOException {
- LocationSpec loaded = fromJson(jsonFixture("fixtures/location-without-credential.json"), LocationSpec.class);
-
- assertEquals(loaded.getSpec(), locationSpec.getSpec());
-
- assertEquals(loaded.getConfig().size(), 1);
- assertEquals(loaded.getConfig().get("identity"), "bob");
- assertNull(loaded.getConfig().get("credential"));
- }
-}
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/3be4fe11/rest/rest-server-jersey/src/test/java/org/apache/brooklyn/rest/domain/LocationSummaryTest.java
----------------------------------------------------------------------
diff --git a/rest/rest-server-jersey/src/test/java/org/apache/brooklyn/rest/domain/LocationSummaryTest.java b/rest/rest-server-jersey/src/test/java/org/apache/brooklyn/rest/domain/LocationSummaryTest.java
deleted file mode 100644
index 0f81b48..0000000
--- a/rest/rest-server-jersey/src/test/java/org/apache/brooklyn/rest/domain/LocationSummaryTest.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.brooklyn.rest.domain;
-
-import java.net.URI;
-import java.util.Map;
-
-import com.google.common.collect.Maps;
-
-public class LocationSummaryTest extends AbstractDomainTest {
-
- @Override
- protected String getPath() {
- return "fixtures/location-summary.json";
- }
-
- @Override
- protected Object getDomainObject() {
- Map<String, URI> links = Maps.newLinkedHashMap();
- links.put("self", URI.create("/v1/locations/123"));
-
- return new LocationSummary("123", "localhost", "localhost", null, null, null, links);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/3be4fe11/rest/rest-server-jersey/src/test/java/org/apache/brooklyn/rest/domain/SensorSummaryTest.java
----------------------------------------------------------------------
diff --git a/rest/rest-server-jersey/src/test/java/org/apache/brooklyn/rest/domain/SensorSummaryTest.java b/rest/rest-server-jersey/src/test/java/org/apache/brooklyn/rest/domain/SensorSummaryTest.java
deleted file mode 100644
index 106d737..0000000
--- a/rest/rest-server-jersey/src/test/java/org/apache/brooklyn/rest/domain/SensorSummaryTest.java
+++ /dev/null
@@ -1,103 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.brooklyn.rest.domain;
-
-import static org.apache.brooklyn.rest.util.RestApiTestUtils.asJson;
-import static org.apache.brooklyn.rest.util.RestApiTestUtils.fromJson;
-import static org.apache.brooklyn.rest.util.RestApiTestUtils.jsonFixture;
-import static org.testng.Assert.assertEquals;
-
-import java.io.IOException;
-import java.net.URI;
-
-import javax.ws.rs.core.UriBuilder;
-
-import org.testng.annotations.AfterMethod;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
-import org.apache.brooklyn.api.entity.EntitySpec;
-import org.apache.brooklyn.api.mgmt.ManagementContext;
-import org.apache.brooklyn.api.sensor.AttributeSensor;
-import org.apache.brooklyn.api.sensor.Sensor;
-import org.apache.brooklyn.core.config.render.RendererHints;
-import org.apache.brooklyn.core.entity.Entities;
-import org.apache.brooklyn.core.sensor.Sensors;
-import org.apache.brooklyn.core.test.entity.TestApplication;
-import org.apache.brooklyn.core.test.entity.TestEntity;
-import org.apache.brooklyn.rest.transform.SensorTransformer;
-
-import com.google.common.collect.ImmutableMap;
-
-public class SensorSummaryTest {
-
- private SensorSummary sensorSummary = new SensorSummary("redis.uptime", "Integer",
- "Description", ImmutableMap.of(
- "self", URI.create("/v1/applications/redis-app/entities/redis-ent/sensors/redis.uptime")));
-
- private TestApplication app;
- private TestEntity entity;
- private ManagementContext mgmt;
-
- @BeforeMethod(alwaysRun = true)
- public void setUp() throws Exception {
- app = TestApplication.Factory.newManagedInstanceForTests();
- mgmt = app.getManagementContext();
- entity = app.createAndManageChild(EntitySpec.create(TestEntity.class));
- }
-
- @AfterMethod(alwaysRun = true)
- public void tearDown() throws Exception {
- if (mgmt != null) Entities.destroyAll(mgmt);
- }
-
- @Test
- public void testSerializeToJSON() throws IOException {
- assertEquals(asJson(sensorSummary), jsonFixture("fixtures/sensor-summary.json"));
- }
-
- @Test
- public void testDeserializeFromJSON() throws IOException {
- assertEquals(fromJson(jsonFixture("fixtures/sensor-summary.json"), SensorSummary.class), sensorSummary);
- }
-
- @Test
- public void testEscapesUriForSensorName() throws IOException {
- Sensor<String> sensor = Sensors.newStringSensor("name with space");
- SensorSummary summary = SensorTransformer.sensorSummary(entity, sensor, UriBuilder.fromPath("/v1"));
- URI selfUri = summary.getLinks().get("self");
-
- String expectedUri = "/v1/applications/" + entity.getApplicationId() + "/entities/" + entity.getId() + "/sensors/" + "name%20with%20space";
-
- assertEquals(selfUri, URI.create(expectedUri));
- }
-
- // Previously failed because immutable-map builder threw exception if put same key multiple times,
- // and the NamedActionWithUrl did not have equals/hashCode
- @Test
- public void testSensorWithMultipleOpenUrlActionsRegistered() throws IOException {
- AttributeSensor<String> sensor = Sensors.newStringSensor("sensor1");
- entity.sensors().set(sensor, "http://myval");
- RendererHints.register(sensor, RendererHints.namedActionWithUrl());
- RendererHints.register(sensor, RendererHints.namedActionWithUrl());
-
- SensorSummary summary = SensorTransformer.sensorSummary(entity, sensor, UriBuilder.fromPath("/"));
-
- assertEquals(summary.getLinks().get("action:open"), URI.create("http://myval"));
- }
-}
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/3be4fe11/rest/rest-server-jersey/src/test/java/org/apache/brooklyn/rest/domain/VersionSummaryTest.java
----------------------------------------------------------------------
diff --git a/rest/rest-server-jersey/src/test/java/org/apache/brooklyn/rest/domain/VersionSummaryTest.java b/rest/rest-server-jersey/src/test/java/org/apache/brooklyn/rest/domain/VersionSummaryTest.java
deleted file mode 100644
index 7bed51b..0000000
--- a/rest/rest-server-jersey/src/test/java/org/apache/brooklyn/rest/domain/VersionSummaryTest.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.brooklyn.rest.domain;
-
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableMap;
-
-public class VersionSummaryTest extends AbstractDomainTest {
-
- @Override
- protected String getPath() {
- return "fixtures/server-version.json";
- }
-
- @Override
- protected Object getDomainObject() {
- BrooklynFeatureSummary features = new BrooklynFeatureSummary(
- "Sample Brooklyn Project com.acme.sample:brooklyn-sample v0.1.0-SNAPSHOT",
- "com.acme.sample.brooklyn-sample",
- "0.1.0.SNAPSHOT",
- "523305000",
- ImmutableMap.of("Brooklyn-Feature-Build-Id", "e0fee1adf795c84eec4735f039503eb18d9c35cc")
- );
- return new VersionSummary(
- "0.7.0-SNAPSHOT",
- "cb4f0a3af2f5042222dd176edc102bfa64e7e0b5",
- "versions",
- ImmutableList.of(features)
- );
- }
-
-}
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/3be4fe11/rest/rest-server-jersey/src/test/java/org/apache/brooklyn/rest/entitlement/AbstractRestApiEntitlementsTest.java
----------------------------------------------------------------------
diff --git a/rest/rest-server-jersey/src/test/java/org/apache/brooklyn/rest/entitlement/AbstractRestApiEntitlementsTest.java b/rest/rest-server-jersey/src/test/java/org/apache/brooklyn/rest/entitlement/AbstractRestApiEntitlementsTest.java
deleted file mode 100644
index 73449ea..0000000
--- a/rest/rest-server-jersey/src/test/java/org/apache/brooklyn/rest/entitlement/AbstractRestApiEntitlementsTest.java
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.brooklyn.rest.entitlement;
-
-import static org.apache.brooklyn.util.http.HttpTool.httpClientBuilder;
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertTrue;
-
-import java.net.URI;
-
-import org.apache.brooklyn.api.entity.EntitySpec;
-import org.apache.brooklyn.api.mgmt.ManagementContext;
-import org.apache.brooklyn.core.entity.Entities;
-import org.apache.brooklyn.core.internal.BrooklynProperties;
-import org.apache.brooklyn.core.mgmt.entitlement.Entitlements;
-import org.apache.brooklyn.core.mgmt.entitlement.PerUserEntitlementManager;
-import org.apache.brooklyn.core.test.entity.LocalManagementContextForTests;
-import org.apache.brooklyn.core.test.entity.TestApplication;
-import org.apache.brooklyn.core.test.entity.TestEntity;
-import org.apache.brooklyn.rest.BrooklynRestApiLauncher;
-import org.apache.brooklyn.rest.BrooklynRestApiLauncherTestFixture;
-import org.apache.brooklyn.util.http.HttpAsserts;
-import org.apache.brooklyn.util.http.HttpTool;
-import org.apache.brooklyn.util.http.HttpToolResponse;
-import org.apache.http.auth.UsernamePasswordCredentials;
-import org.apache.http.client.HttpClient;
-import org.testng.annotations.AfterMethod;
-import org.testng.annotations.BeforeMethod;
-
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.Iterables;
-
-/**
- * Sets up the REST api with some standard users, ready for testing entitlements.
- */
-public abstract class AbstractRestApiEntitlementsTest extends BrooklynRestApiLauncherTestFixture {
-
- protected ManagementContext mgmt;
- protected TestApplication app;
- protected TestEntity entity;
-
- @BeforeMethod(alwaysRun=true)
- public void setUp() throws Exception {
- BrooklynProperties props = BrooklynProperties.Factory.newEmpty();
- props.put(Entitlements.GLOBAL_ENTITLEMENT_MANAGER.getName(), PerUserEntitlementManager.class.getName());
- props.put(PerUserEntitlementManager.PER_USER_ENTITLEMENTS_CONFIG_PREFIX+".myRoot", "root");
- props.put(PerUserEntitlementManager.PER_USER_ENTITLEMENTS_CONFIG_PREFIX+".myReadonly", "readonly");
- props.put(PerUserEntitlementManager.PER_USER_ENTITLEMENTS_CONFIG_PREFIX+".myMinimal", "minimal");
- props.put(PerUserEntitlementManager.PER_USER_ENTITLEMENTS_CONFIG_PREFIX+".myCustom", StaticDelegatingEntitlementManager.class.getName());
-
- mgmt = LocalManagementContextForTests.builder(true).useProperties(props).build();
- app = mgmt.getEntityManager().createEntity(EntitySpec.create(TestApplication.class)
- .child(EntitySpec.create(TestEntity.class))
- .configure(TestEntity.CONF_NAME, "myname"));
- entity = (TestEntity) Iterables.getOnlyElement(app.getChildren());
-
- useServerForTest(BrooklynRestApiLauncher.launcher()
- .managementContext(mgmt)
- .forceUseOfDefaultCatalogWithJavaClassPath(true)
- .securityProvider(AuthenticateAnyoneSecurityProvider.class)
- .start());
- }
-
- @AfterMethod(alwaysRun=true)
- public void tearDown() throws Exception {
- if (mgmt != null) Entities.destroyAll(mgmt);
- }
-
- protected HttpClient newClient(String user) throws Exception {
- return httpClientBuilder()
- .uri(getBaseUri())
- .credentials(new UsernamePasswordCredentials(user, "ignoredPassword"))
- .build();
- }
-
- protected String httpGet(String user, String path) throws Exception {
- HttpToolResponse response = HttpTool.httpGet(newClient(user), URI.create(getBaseUri()).resolve(path), ImmutableMap.<String, String>of());
- assertTrue(HttpAsserts.isHealthyStatusCode(response.getResponseCode()), "code="+response.getResponseCode()+"; reason="+response.getReasonPhrase());
- return response.getContentAsString();
- }
-
- protected String assertPermitted(String user, String path) throws Exception {
- return httpGet(user, path);
- }
-
- protected void assertForbidden(String user, String path) throws Exception {
- HttpToolResponse response = HttpTool.httpGet(newClient(user), URI.create(getBaseUri()).resolve(path), ImmutableMap.<String, String>of());
- assertEquals(response.getResponseCode(), 403, "code="+response.getResponseCode()+"; reason="+response.getReasonPhrase()+"; content="+response.getContentAsString());
- }
-
- protected void assert404(String user, String path) throws Exception {
- HttpToolResponse response = HttpTool.httpGet(newClient(user), URI.create(getBaseUri()).resolve(path), ImmutableMap.<String, String>of());
- assertEquals(response.getResponseCode(), 404, "code="+response.getResponseCode()+"; reason="+response.getReasonPhrase()+"; content="+response.getContentAsString());
- }
-}
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/3be4fe11/rest/rest-server-jersey/src/test/java/org/apache/brooklyn/rest/entitlement/ActivityApiEntitlementsTest.java
----------------------------------------------------------------------
diff --git a/rest/rest-server-jersey/src/test/java/org/apache/brooklyn/rest/entitlement/ActivityApiEntitlementsTest.java b/rest/rest-server-jersey/src/test/java/org/apache/brooklyn/rest/entitlement/ActivityApiEntitlementsTest.java
deleted file mode 100644
index 2f1cc7b..0000000
--- a/rest/rest-server-jersey/src/test/java/org/apache/brooklyn/rest/entitlement/ActivityApiEntitlementsTest.java
+++ /dev/null
@@ -1,122 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.brooklyn.rest.entitlement;
-
-import static org.testng.Assert.assertEquals;
-
-import java.util.Map;
-import java.util.Set;
-
-import org.apache.brooklyn.api.entity.EntitySpec;
-import org.apache.brooklyn.api.location.Location;
-import org.apache.brooklyn.api.mgmt.Task;
-import org.apache.brooklyn.api.mgmt.entitlement.EntitlementClass;
-import org.apache.brooklyn.api.mgmt.entitlement.EntitlementContext;
-import org.apache.brooklyn.api.mgmt.entitlement.EntitlementManager;
-import org.apache.brooklyn.core.entity.BrooklynConfigKeys;
-import org.apache.brooklyn.core.mgmt.BrooklynTaskTags;
-import org.apache.brooklyn.core.mgmt.entitlement.Entitlements;
-import org.apache.brooklyn.core.test.entity.TestApplication;
-import org.apache.brooklyn.entity.machine.MachineEntity;
-import org.apache.brooklyn.entity.software.base.AbstractSoftwareProcessStreamsTest;
-import org.apache.brooklyn.util.core.task.TaskPredicates;
-import org.apache.brooklyn.util.text.StringPredicates;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
-
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.Maps;
-
-@Test(singleThreaded = true)
-public class ActivityApiEntitlementsTest extends AbstractRestApiEntitlementsTest {
-
- protected MachineEntity machineEntity;
- protected Task<?> subTask;
- protected Map<String, String> streams;
-
- @BeforeMethod(alwaysRun=true)
- @Override
- public void setUp() throws Exception {
- super.setUp();
-
- machineEntity = app.addChild(EntitySpec.create(MachineEntity.class)
- .configure(BrooklynConfigKeys.SKIP_ON_BOX_BASE_DIR_RESOLUTION, true)
- .location(TestApplication.LOCALHOST_PROVISIONER_SPEC));
- machineEntity.start(ImmutableList.<Location>of());
-
- machineEntity.execCommand("echo myval");
-
- Set<Task<?>> tasks = BrooklynTaskTags.getTasksInEntityContext(mgmt.getExecutionManager(), machineEntity);
- String taskNameRegex = "ssh: echo myval";
-
- streams = Maps.newLinkedHashMap();
- subTask = AbstractSoftwareProcessStreamsTest.findTaskOrSubTask(tasks, TaskPredicates.displayNameSatisfies(StringPredicates.matchesRegex(taskNameRegex))).get();
- for (String streamId : ImmutableList.of("stdin", "stdout", "stderr")) {
- streams.put(streamId, AbstractSoftwareProcessStreamsTest.getStreamOrFail(subTask, streamId));
- }
- }
-
- @Test(groups = "Integration")
- public void testGetTask() throws Exception {
- String path = "/v1/activities/"+subTask.getId();
- assertPermitted("myRoot", path);
- assertPermitted("myReadonly", path);
- assertForbidden("myMinimal", path);
- assertForbidden("unrecognisedUser", path);
- }
-
- @Test(groups = "Integration")
- public void testGetStream() throws Exception {
- String pathPrefix = "/v1/activities/"+subTask.getId()+"/stream/";
- for (Map.Entry<String, String> entry : streams.entrySet()) {
- String streamId = entry.getKey();
- String expectedStream = entry.getValue();
-
- assertEquals(httpGet("myRoot", pathPrefix+streamId), expectedStream);
- assertEquals(httpGet("myReadonly", pathPrefix+streamId), expectedStream);
- assertForbidden("myMinimal", pathPrefix+streamId);
- assertForbidden("unrecognisedUser", pathPrefix+streamId);
-
- StaticDelegatingEntitlementManager.setDelegate(new SeeSelectiveStreams(streamId));
- assertEquals(httpGet("myCustom", pathPrefix+streamId), expectedStream);
-
- StaticDelegatingEntitlementManager.setDelegate(new SeeSelectiveStreams("differentStreamId"));
- assertForbidden("myCustom", pathPrefix+streamId);
- }
- }
-
- public static class SeeSelectiveStreams implements EntitlementManager {
- private final String regex;
-
- public SeeSelectiveStreams(String regex) {
- this.regex = regex;
- }
- @Override
- @SuppressWarnings("unchecked")
- public <T> boolean isEntitled(EntitlementContext context, EntitlementClass<T> entitlementClass, T entitlementClassArgument) {
- String type = entitlementClass.entitlementClassIdentifier();
- if (Entitlements.SEE_ACTIVITY_STREAMS.entitlementClassIdentifier().equals(type)) {
- Entitlements.TaskAndItem<String> pair = (Entitlements.TaskAndItem<String>) entitlementClassArgument;
- return pair.getItem().matches(regex);
- } else {
- return true;
- }
- }
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/3be4fe11/rest/rest-server-jersey/src/test/java/org/apache/brooklyn/rest/entitlement/AuthenticateAnyoneSecurityProvider.java
----------------------------------------------------------------------
diff --git a/rest/rest-server-jersey/src/test/java/org/apache/brooklyn/rest/entitlement/AuthenticateAnyoneSecurityProvider.java b/rest/rest-server-jersey/src/test/java/org/apache/brooklyn/rest/entitlement/AuthenticateAnyoneSecurityProvider.java
deleted file mode 100644
index b7264b2..0000000
--- a/rest/rest-server-jersey/src/test/java/org/apache/brooklyn/rest/entitlement/AuthenticateAnyoneSecurityProvider.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.brooklyn.rest.entitlement;
-
-import javax.servlet.http.HttpSession;
-
-import org.apache.brooklyn.rest.security.provider.SecurityProvider;
-
-public class AuthenticateAnyoneSecurityProvider implements SecurityProvider {
-
- @Override
- public boolean isAuthenticated(HttpSession session) {
- return false;
- }
-
- @Override
- public boolean authenticate(HttpSession session, String user, String password) {
- return user != null;
- }
-
- @Override
- public boolean logout(HttpSession session) {
- return false;
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/3be4fe11/rest/rest-server-jersey/src/test/java/org/apache/brooklyn/rest/entitlement/EntityConfigApiEntitlementsTest.java
----------------------------------------------------------------------
diff --git a/rest/rest-server-jersey/src/test/java/org/apache/brooklyn/rest/entitlement/EntityConfigApiEntitlementsTest.java b/rest/rest-server-jersey/src/test/java/org/apache/brooklyn/rest/entitlement/EntityConfigApiEntitlementsTest.java
deleted file mode 100644
index cbda515..0000000
--- a/rest/rest-server-jersey/src/test/java/org/apache/brooklyn/rest/entitlement/EntityConfigApiEntitlementsTest.java
+++ /dev/null
@@ -1,103 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.brooklyn.rest.entitlement;
-
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertFalse;
-
-import org.apache.brooklyn.api.entity.Entity;
-import org.apache.brooklyn.api.mgmt.entitlement.EntitlementClass;
-import org.apache.brooklyn.api.mgmt.entitlement.EntitlementContext;
-import org.apache.brooklyn.api.mgmt.entitlement.EntitlementManager;
-import org.apache.brooklyn.api.sensor.AttributeSensor;
-import org.apache.brooklyn.core.config.render.RendererHints;
-import org.apache.brooklyn.core.mgmt.entitlement.Entitlements;
-import org.apache.brooklyn.core.mgmt.entitlement.Entitlements.EntityAndItem;
-import org.apache.brooklyn.core.test.entity.TestEntity;
-import org.apache.brooklyn.rest.api.SensorApi;
-import org.apache.brooklyn.rest.resources.SensorResource;
-import org.apache.brooklyn.test.Asserts;
-import org.testng.annotations.Test;
-
-/**
- * Test the {@link SensorApi} implementation.
- * <p>
- * Check that {@link SensorResource} correctly renders {@link AttributeSensor}
- * values, including {@link RendererHints.DisplayValue} hints.
- */
-@Test(singleThreaded = true)
-public class EntityConfigApiEntitlementsTest extends AbstractRestApiEntitlementsTest {
-
- @Test(groups = "Integration")
- public void testGet() throws Exception {
- String path = "/v1/applications/"+app.getId()+"/entities/"+entity.getId()+"/config/"+TestEntity.CONF_NAME.getName();
- String val = "\"myname\"";
-
- assertEquals(httpGet("myRoot", path), val);
- assertEquals(httpGet("myReadonly", path), val);
- assert404("myMinimal", path); // can't see app, to retrieve entity
- assert404("unrecognisedUser", path);
-
- StaticDelegatingEntitlementManager.setDelegate(new SeeSelectiveConfig(entity, TestEntity.CONF_NAME.getName()));
- assertEquals(httpGet("myCustom", path), val);
-
- StaticDelegatingEntitlementManager.setDelegate(new SeeSelectiveConfig(entity, "differentConfName"));
- assertForbidden("myCustom", path);
- }
-
- @Test(groups = "Integration")
- public void testCurrentState() throws Exception {
- String path = "/v1/applications/"+app.getId()+"/entities/"+entity.getId()+"/config/current-state";
- String confName = TestEntity.CONF_NAME.getName();
- String regex = ".*"+confName+".*myname.*";
-
- Asserts.assertStringMatchesRegex(httpGet("myRoot", path), regex);
- Asserts.assertStringMatchesRegex(httpGet("myReadonly", path), regex);
- assert404("myMinimal", path); // can't see app, to retrieve entity
- assert404("unrecognisedUser", path);
-
- StaticDelegatingEntitlementManager.setDelegate(new SeeSelectiveConfig(entity, confName));
- Asserts.assertStringMatchesRegex(httpGet("myCustom", path), regex);
-
- StaticDelegatingEntitlementManager.setDelegate(new SeeSelectiveConfig(entity, "differentConfName"));
- String resp = httpGet("myCustom", path);
- assertFalse(resp.matches(regex), "resp="+resp);
- }
-
- public static class SeeSelectiveConfig implements EntitlementManager {
- private final Entity entity;
- private final String regex;
-
- public SeeSelectiveConfig(Entity entity, String regex) {
- this.entity = entity;
- this.regex = regex;
- }
- @Override
- @SuppressWarnings("unchecked")
- public <T> boolean isEntitled(EntitlementContext context, EntitlementClass<T> entitlementClass, T entitlementClassArgument) {
- String type = entitlementClass.entitlementClassIdentifier();
- if (Entitlements.SEE_CONFIG.entitlementClassIdentifier().equals(type)) {
- EntityAndItem<String> entityAndItem = (EntityAndItem<String>) entitlementClassArgument;
- return entity.equals(entityAndItem.getEntity()) && entityAndItem.getItem().matches(regex);
- } else {
- return true;
- }
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/3be4fe11/rest/rest-server-jersey/src/test/java/org/apache/brooklyn/rest/entitlement/SensorApiEntitlementsTest.java
----------------------------------------------------------------------
diff --git a/rest/rest-server-jersey/src/test/java/org/apache/brooklyn/rest/entitlement/SensorApiEntitlementsTest.java b/rest/rest-server-jersey/src/test/java/org/apache/brooklyn/rest/entitlement/SensorApiEntitlementsTest.java
deleted file mode 100644
index dab72ec..0000000
--- a/rest/rest-server-jersey/src/test/java/org/apache/brooklyn/rest/entitlement/SensorApiEntitlementsTest.java
+++ /dev/null
@@ -1,108 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.brooklyn.rest.entitlement;
-
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertFalse;
-
-import org.apache.brooklyn.api.entity.Entity;
-import org.apache.brooklyn.api.mgmt.entitlement.EntitlementClass;
-import org.apache.brooklyn.api.mgmt.entitlement.EntitlementContext;
-import org.apache.brooklyn.api.mgmt.entitlement.EntitlementManager;
-import org.apache.brooklyn.api.sensor.AttributeSensor;
-import org.apache.brooklyn.core.config.render.RendererHints;
-import org.apache.brooklyn.core.mgmt.entitlement.Entitlements;
-import org.apache.brooklyn.core.mgmt.entitlement.Entitlements.EntityAndItem;
-import org.apache.brooklyn.core.test.entity.TestEntity;
-import org.apache.brooklyn.rest.api.SensorApi;
-import org.apache.brooklyn.rest.resources.SensorResource;
-import org.apache.brooklyn.test.Asserts;
-import org.testng.annotations.Test;
-
-/**
- * Test the {@link SensorApi} implementation.
- * <p>
- * Check that {@link SensorResource} correctly renders {@link AttributeSensor}
- * values, including {@link RendererHints.DisplayValue} hints.
- */
-@Test(singleThreaded = true)
-public class SensorApiEntitlementsTest extends AbstractRestApiEntitlementsTest {
-
- @Test(groups = "Integration")
- public void testGet() throws Exception {
- entity.sensors().set(TestEntity.NAME, "myval");
-
- String sensorName = TestEntity.NAME.getName();
- String path = "/v1/applications/"+app.getId()+"/entities/"+entity.getId()+"/sensors/"+sensorName;
- String val = "\"myval\"";
-
- assertEquals(httpGet("myRoot", path), val);
- assertEquals(httpGet("myReadonly", path), val);
- assert404("myMinimal", path); // can't see app, to retrieve entity
- assert404("unrecognisedUser", path);
-
- StaticDelegatingEntitlementManager.setDelegate(new SeeSelectiveSensor(entity, sensorName));
- assertEquals(httpGet("myCustom", path), val);
-
- StaticDelegatingEntitlementManager.setDelegate(new SeeSelectiveSensor(entity, "differentConfName"));
- assertForbidden("myCustom", path);
- }
-
- @Test(groups = "Integration")
- public void testCurrentState() throws Exception {
- entity.sensors().set(TestEntity.NAME, "myval");
-
- String path = "/v1/applications/"+app.getId()+"/entities/"+entity.getId()+"/sensors/current-state";
- String sensorName = TestEntity.NAME.getName();
- String regex = ".*"+sensorName+".*myval.*";
-
- Asserts.assertStringMatchesRegex(httpGet("myRoot", path), regex);
- Asserts.assertStringMatchesRegex(httpGet("myReadonly", path), regex);
- assert404("myMinimal", path); // can't see app, to retrieve entity
- assert404("unrecognisedUser", path);
-
- StaticDelegatingEntitlementManager.setDelegate(new SeeSelectiveSensor(entity, sensorName));
- Asserts.assertStringMatchesRegex(httpGet("myCustom", path), regex);
-
- StaticDelegatingEntitlementManager.setDelegate(new SeeSelectiveSensor(entity, "differentSensorName"));
- String resp = httpGet("myCustom", path);
- assertFalse(resp.matches(regex), "resp="+resp);
- }
-
- public static class SeeSelectiveSensor implements EntitlementManager {
- private final Entity entity;
- private final String regex;
-
- public SeeSelectiveSensor(Entity entity, String regex) {
- this.entity = entity;
- this.regex = regex;
- }
- @Override
- @SuppressWarnings("unchecked")
- public <T> boolean isEntitled(EntitlementContext context, EntitlementClass<T> entitlementClass, T entitlementClassArgument) {
- String type = entitlementClass.entitlementClassIdentifier();
- if (Entitlements.SEE_SENSOR.entitlementClassIdentifier().equals(type)) {
- EntityAndItem<String> entityAndItem = (EntityAndItem<String>) entitlementClassArgument;
- return entity.equals(entityAndItem.getEntity()) && entityAndItem.getItem().matches(regex);
- } else {
- return true;
- }
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/3be4fe11/rest/rest-server-jersey/src/test/java/org/apache/brooklyn/rest/entitlement/ServerApiEntitlementsTest.java
----------------------------------------------------------------------
diff --git a/rest/rest-server-jersey/src/test/java/org/apache/brooklyn/rest/entitlement/ServerApiEntitlementsTest.java b/rest/rest-server-jersey/src/test/java/org/apache/brooklyn/rest/entitlement/ServerApiEntitlementsTest.java
deleted file mode 100644
index afa42cb..0000000
--- a/rest/rest-server-jersey/src/test/java/org/apache/brooklyn/rest/entitlement/ServerApiEntitlementsTest.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.brooklyn.rest.entitlement;
-
-import org.testng.annotations.Test;
-
-@Test(singleThreaded = true)
-public class ServerApiEntitlementsTest extends AbstractRestApiEntitlementsTest {
-
- @Test(groups = "Integration")
- public void testGetHealthy() throws Exception {
- String path = "/v1/server/up";
- assertPermitted("myRoot", path);
- assertForbidden("myReadonly", path);
- assertForbidden("myMinimal", path);
- assertForbidden("unrecognisedUser", path);
- }
-}
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/3be4fe11/rest/rest-server-jersey/src/test/java/org/apache/brooklyn/rest/entitlement/StaticDelegatingEntitlementManager.java
----------------------------------------------------------------------
diff --git a/rest/rest-server-jersey/src/test/java/org/apache/brooklyn/rest/entitlement/StaticDelegatingEntitlementManager.java b/rest/rest-server-jersey/src/test/java/org/apache/brooklyn/rest/entitlement/StaticDelegatingEntitlementManager.java
deleted file mode 100644
index 4370ad6..0000000
--- a/rest/rest-server-jersey/src/test/java/org/apache/brooklyn/rest/entitlement/StaticDelegatingEntitlementManager.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.brooklyn.rest.entitlement;
-
-import org.apache.brooklyn.api.mgmt.entitlement.EntitlementClass;
-import org.apache.brooklyn.api.mgmt.entitlement.EntitlementContext;
-import org.apache.brooklyn.api.mgmt.entitlement.EntitlementManager;
-
-public class StaticDelegatingEntitlementManager implements EntitlementManager {
-
- private static volatile EntitlementManager delegate;
-
- public static void setDelegate(EntitlementManager val) {
- delegate = val;
- }
-
- @Override
- public <T> boolean isEntitled(EntitlementContext context, EntitlementClass<T> entitlementClass, T entitlementClassArgument) {
- return (delegate != null) ? delegate.isEntitled(context, entitlementClass, entitlementClassArgument) : false;
- }
-}
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/3be4fe11/rest/rest-server-jersey/src/test/java/org/apache/brooklyn/rest/resources/AccessResourceTest.java
----------------------------------------------------------------------
diff --git a/rest/rest-server-jersey/src/test/java/org/apache/brooklyn/rest/resources/AccessResourceTest.java b/rest/rest-server-jersey/src/test/java/org/apache/brooklyn/rest/resources/AccessResourceTest.java
deleted file mode 100644
index 0839ea5..0000000
--- a/rest/rest-server-jersey/src/test/java/org/apache/brooklyn/rest/resources/AccessResourceTest.java
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.brooklyn.rest.resources;
-
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertFalse;
-import static org.testng.Assert.assertTrue;
-
-import javax.ws.rs.core.Response;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.testng.annotations.Test;
-
-import org.apache.brooklyn.rest.domain.AccessSummary;
-import org.apache.brooklyn.rest.testing.BrooklynRestResourceTest;
-
-import com.sun.jersey.api.client.ClientResponse;
-
-@Test(singleThreaded = true)
-public class AccessResourceTest extends BrooklynRestResourceTest {
-
- @SuppressWarnings("unused")
- private static final Logger log = LoggerFactory.getLogger(AccessResourceTest.class);
-
- @Test
- public void testGetAndSetAccessControl() throws Exception {
- // Default is everything allowed
- AccessSummary summary = client().resource("/v1/access").get(AccessSummary.class);
- assertTrue(summary.isLocationProvisioningAllowed());
-
- // Forbid location provisioning
- ClientResponse response = client().resource(
- "/v1/access/locationProvisioningAllowed")
- .queryParam("allowed", "false")
- .post(ClientResponse.class);
- assertEquals(response.getStatus(), Response.Status.OK.getStatusCode());
-
- AccessSummary summary2 = client().resource("/v1/access").get(AccessSummary.class);
- assertFalse(summary2.isLocationProvisioningAllowed());
-
- // Allow location provisioning
- ClientResponse response2 = client().resource(
- "/v1/access/locationProvisioningAllowed")
- .queryParam("allowed", "true")
- .post(ClientResponse.class);
- assertEquals(response2.getStatus(), Response.Status.OK.getStatusCode());
-
- AccessSummary summary3 = client().resource("/v1/access").get(AccessSummary.class);
- assertTrue(summary3.isLocationProvisioningAllowed());
- }
-}
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/3be4fe11/rest/rest-server-jersey/src/test/java/org/apache/brooklyn/rest/resources/ApidocResourceTest.java
----------------------------------------------------------------------
diff --git a/rest/rest-server-jersey/src/test/java/org/apache/brooklyn/rest/resources/ApidocResourceTest.java b/rest/rest-server-jersey/src/test/java/org/apache/brooklyn/rest/resources/ApidocResourceTest.java
deleted file mode 100644
index 2064508..0000000
--- a/rest/rest-server-jersey/src/test/java/org/apache/brooklyn/rest/resources/ApidocResourceTest.java
+++ /dev/null
@@ -1,173 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.brooklyn.rest.resources;
-
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertFalse;
-import io.swagger.annotations.Api;
-import io.swagger.models.Operation;
-import io.swagger.models.Path;
-import io.swagger.models.Swagger;
-
-import java.util.Collection;
-
-import org.apache.brooklyn.rest.BrooklynRestApi;
-import org.apache.brooklyn.rest.api.CatalogApi;
-import org.apache.brooklyn.rest.api.EffectorApi;
-import org.apache.brooklyn.rest.api.EntityApi;
-import org.apache.brooklyn.rest.filter.SwaggerFilter;
-import org.apache.brooklyn.rest.testing.BrooklynRestResourceTest;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.testng.annotations.Test;
-
-import com.google.common.base.Function;
-import com.google.common.base.Joiner;
-import com.google.common.base.Predicate;
-import com.google.common.collect.Collections2;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.Iterables;
-import com.sun.jersey.api.core.ClassNamesResourceConfig;
-import com.sun.jersey.spi.container.servlet.ServletContainer;
-import com.sun.jersey.test.framework.AppDescriptor;
-import com.sun.jersey.test.framework.JerseyTest;
-import com.sun.jersey.test.framework.WebAppDescriptor;
-import com.sun.jersey.test.framework.spi.container.TestContainerException;
-import com.sun.jersey.test.framework.spi.container.TestContainerFactory;
-import com.sun.jersey.test.framework.spi.container.grizzly2.web.GrizzlyWebTestContainerFactory;
-
-/**
- * @author Adam Lowe
- */
-@Test(singleThreaded = true)
-public class ApidocResourceTest extends BrooklynRestResourceTest {
-
- private static final Logger log = LoggerFactory.getLogger(ApidocResourceTest.class);
-
- @Override
- protected JerseyTest createJerseyTest() {
- return new JerseyTest() {
- @Override
- protected AppDescriptor configure() {
- return new WebAppDescriptor.Builder(
- ImmutableMap.of(
- ServletContainer.RESOURCE_CONFIG_CLASS, ClassNamesResourceConfig.class.getName(),
- ClassNamesResourceConfig.PROPERTY_CLASSNAMES, getResourceClassnames()))
- .addFilter(SwaggerFilter.class, "SwaggerFilter").build();
- }
-
- @Override
- protected TestContainerFactory getTestContainerFactory() throws TestContainerException {
- return new GrizzlyWebTestContainerFactory();
- }
-
- private String getResourceClassnames() {
- Iterable<String> classnames = Collections2.transform(config.getClasses(), new Function<Class<?>, String>() {
- @Override
- public String apply(Class<?> clazz) {
- return clazz.getName();
- }
- });
- classnames = Iterables.concat(classnames, Collections2.transform(config.getSingletons(), new Function<Object, String>() {
- @Override
- public String apply(Object singleton) {
- return singleton.getClass().getName();
- }
- }));
- return Joiner.on(';').join(classnames);
- }
- };
- }
-
- @Override
- protected void addBrooklynResources() {
- for (Object o : BrooklynRestApi.getApidocResources()) {
- addResource(o);
- }
- super.addBrooklynResources();
- }
-
- @Test(enabled = false)
- public void testRootSerializesSensibly() throws Exception {
- String data = resource("/v1/apidoc/swagger.json").get(String.class);
- log.info("apidoc gives: "+data);
- // make sure no scala gets in
- assertFalse(data.contains("$"));
- assertFalse(data.contains("scala"));
- // make sure it's an appropriate swagger 2.0 json
- Swagger swagger = resource("/v1/apidoc/swagger.json").get(Swagger.class);
- assertEquals(swagger.getSwagger(), "2.0");
- }
-
- @Test(enabled = false)
- public void testCountRestResources() throws Exception {
- Swagger swagger = resource("/v1/apidoc/swagger.json").get(Swagger.class);
- assertEquals(swagger.getTags().size(), 1 + Iterables.size(BrooklynRestApi.getBrooklynRestResources()));
- }
-
- @Test(enabled = false)
- public void testApiDocDetails() throws Exception {
- Swagger swagger = resource("/v1/apidoc/swagger.json").get(Swagger.class);
- Collection<Operation> operations = getTaggedOperations(swagger, ApidocResource.class.getAnnotation(Api.class).value());
- assertEquals(operations.size(), 2, "ops="+operations);
- }
-
- @Test(enabled = false)
- public void testEffectorDetails() throws Exception {
- Swagger swagger = resource("/v1/apidoc/swagger.json").get(Swagger.class);
- Collection<Operation> operations = getTaggedOperations(swagger, EffectorApi.class.getAnnotation(Api.class).value());
- assertEquals(operations.size(), 2, "ops="+operations);
- }
-
- @Test(enabled = false)
- public void testEntityDetails() throws Exception {
- Swagger swagger = resource("/v1/apidoc/swagger.json").get(Swagger.class);
- Collection<Operation> operations = getTaggedOperations(swagger, EntityApi.class.getAnnotation(Api.class).value());
- assertEquals(operations.size(), 14, "ops="+operations);
- }
-
- @Test(enabled = false)
- public void testCatalogDetails() throws Exception {
- Swagger swagger = resource("/v1/apidoc/swagger.json").get(Swagger.class);
- Collection<Operation> operations = getTaggedOperations(swagger, CatalogApi.class.getAnnotation(Api.class).value());
- assertEquals(operations.size(), 22, "ops="+operations);
- }
-
- /**
- * Retrieves all operations tagged the given tag from the given swagger spec.
- */
- private Collection<Operation> getTaggedOperations(Swagger swagger, final String requiredTag) {
- Iterable<Operation> allOperations = Iterables.concat(Collections2.transform(swagger.getPaths().values(),
- new Function<Path, Collection<Operation>>() {
- @Override
- public Collection<Operation> apply(Path path) {
- return path.getOperations();
- }
- }));
-
- return Collections2.filter(ImmutableList.copyOf(allOperations), new Predicate<Operation>() {
- @Override
- public boolean apply(Operation operation) {
- return operation.getTags().contains(requiredTag);
- }
- });
- }
-}
-
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/3be4fe11/rest/rest-server-jersey/src/test/java/org/apache/brooklyn/rest/resources/ApplicationResourceIntegrationTest.java
----------------------------------------------------------------------
diff --git a/rest/rest-server-jersey/src/test/java/org/apache/brooklyn/rest/resources/ApplicationResourceIntegrationTest.java b/rest/rest-server-jersey/src/test/java/org/apache/brooklyn/rest/resources/ApplicationResourceIntegrationTest.java
deleted file mode 100644
index 865b6f7..0000000
--- a/rest/rest-server-jersey/src/test/java/org/apache/brooklyn/rest/resources/ApplicationResourceIntegrationTest.java
+++ /dev/null
@@ -1,133 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.brooklyn.rest.resources;
-
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertTrue;
-
-import java.net.URI;
-import java.util.Set;
-
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.testng.annotations.Test;
-import org.apache.brooklyn.core.entity.lifecycle.Lifecycle;
-import org.apache.brooklyn.rest.domain.ApplicationSpec;
-import org.apache.brooklyn.rest.domain.ApplicationSummary;
-import org.apache.brooklyn.rest.domain.EntitySpec;
-import org.apache.brooklyn.rest.domain.EntitySummary;
-import org.apache.brooklyn.rest.domain.SensorSummary;
-import org.apache.brooklyn.rest.testing.BrooklynRestResourceTest;
-import org.apache.brooklyn.test.Asserts;
-import org.apache.brooklyn.util.collections.MutableMap;
-
-import com.google.common.base.Predicate;
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.Iterables;
-import com.sun.jersey.api.client.ClientResponse;
-import com.sun.jersey.api.client.GenericType;
-
-@Test(singleThreaded = true)
-public class ApplicationResourceIntegrationTest extends BrooklynRestResourceTest {
-
- @SuppressWarnings("unused")
- private static final Logger log = LoggerFactory.getLogger(ApplicationResourceIntegrationTest.class);
-
- private final ApplicationSpec redisSpec = ApplicationSpec.builder().name("redis-app")
- .entities(ImmutableSet.of(new EntitySpec("redis-ent", "org.apache.brooklyn.entity.nosql.redis.RedisStore")))
- .locations(ImmutableSet.of("localhost"))
- .build();
-
- @Test(groups="Integration")
- public void testDeployRedisApplication() throws Exception {
- ClientResponse response = clientDeploy(redisSpec);
-
- assertEquals(response.getStatus(), 201);
- assertEquals(getManagementContext().getApplications().size(), 1);
- assertTrue(response.getLocation().getPath().startsWith("/v1/applications/"), "path="+response.getLocation().getPath()); // path uses id, rather than app name
-
- waitForApplicationToBeRunning(response.getLocation());
- }
-
- @Test(groups="Integration", dependsOnMethods = "testDeployRedisApplication")
- public void testListEntities() {
- Set<EntitySummary> entities = client().resource("/v1/applications/redis-app/entities")
- .get(new GenericType<Set<EntitySummary>>() {});
-
- for (EntitySummary entity : entities) {
- client().resource(entity.getLinks().get("self")).get(ClientResponse.class);
- // TODO assertions on the above call?
-
- Set<EntitySummary> children = client().resource(entity.getLinks().get("children"))
- .get(new GenericType<Set<EntitySummary>>() {});
- assertEquals(children.size(), 0);
- }
- }
-
- @Test(groups="Integration", dependsOnMethods = "testDeployRedisApplication")
- public void testListSensorsRedis() {
- Set<SensorSummary> sensors = client().resource("/v1/applications/redis-app/entities/redis-ent/sensors")
- .get(new GenericType<Set<SensorSummary>>() {});
- assertTrue(sensors.size() > 0);
- SensorSummary uptime = Iterables.find(sensors, new Predicate<SensorSummary>() {
- @Override
- public boolean apply(SensorSummary sensorSummary) {
- return sensorSummary.getName().equals("redis.uptime");
- }
- });
- assertEquals(uptime.getType(), "java.lang.Integer");
- }
-
- @Test(groups="Integration", dependsOnMethods = { "testListSensorsRedis", "testListEntities" })
- public void testTriggerRedisStopEffector() throws Exception {
- ClientResponse response = client().resource("/v1/applications/redis-app/entities/redis-ent/effectors/stop")
- .type(MediaType.APPLICATION_JSON_TYPE)
- .post(ClientResponse.class, ImmutableMap.of());
- assertEquals(response.getStatus(), Response.Status.ACCEPTED.getStatusCode());
-
- final URI stateSensor = URI.create("/v1/applications/redis-app/entities/redis-ent/sensors/service.state");
- final String expectedStatus = Lifecycle.STOPPED.toString();
- Asserts.succeedsEventually(MutableMap.of("timeout", 60 * 1000), new Runnable() {
- public void run() {
- // Accept with and without quotes; if don't specify "Accepts" header, then
- // might get back json or plain text (depending on compiler / java runtime
- // used for SensorApi!)
- String val = client().resource(stateSensor).get(String.class);
- assertTrue(expectedStatus.equalsIgnoreCase(val) || ("\""+expectedStatus+"\"").equalsIgnoreCase(val), "state="+val);
- }
- });
- }
-
- @Test(groups="Integration", dependsOnMethods = "testTriggerRedisStopEffector" )
- public void testDeleteRedisApplication() throws Exception {
- int size = getManagementContext().getApplications().size();
- ClientResponse response = client().resource("/v1/applications/redis-app")
- .delete(ClientResponse.class);
-
- waitForPageNotFoundResponse("/v1/applications/redis-app", ApplicationSummary.class);
-
- assertEquals(response.getStatus(), Response.Status.ACCEPTED.getStatusCode());
- assertEquals(getManagementContext().getApplications().size(), size-1);
- }
-
-}