You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by ma...@apache.org on 2012/10/09 02:55:08 UTC
svn commit: r1395830 [2/2] - in /incubator/ambari/branches/AMBARI-666: ./
ambari-api/src/main/java/org/apache/ambari/api/handlers/
ambari-api/src/main/java/org/apache/ambari/api/query/
ambari-api/src/main/java/org/apache/ambari/api/resource/ ambari-api...
Modified: incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/services/ServiceService.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/services/ServiceService.java?rev=1395830&r1=1395829&r2=1395830&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/services/ServiceService.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/services/ServiceService.java Tue Oct 9 00:55:06 2012
@@ -18,8 +18,8 @@
package org.apache.ambari.api.services;
-import org.apache.ambari.api.resource.ResourceDefinition;
-import org.apache.ambari.api.resource.ServiceResourceDefinition;
+import org.apache.ambari.api.resources.ResourceDefinition;
+import org.apache.ambari.api.resources.ServiceResourceDefinition;
import javax.ws.rs.*;
import javax.ws.rs.core.*;
@@ -57,7 +57,7 @@ public class ServiceService extends Base
public Response getService(@Context HttpHeaders headers, @Context UriInfo ui,
@PathParam("serviceName") String serviceName) {
- return handleRequest(headers, ui, Request.Type.GET,
+ return handleRequest(headers, null, ui, Request.Type.GET,
createResourceDefinition(serviceName, m_clusterName));
}
@@ -72,7 +72,7 @@ public class ServiceService extends Base
@GET
@Produces("text/plain")
public Response getServices(@Context HttpHeaders headers, @Context UriInfo ui) {
- return handleRequest(headers, ui, Request.Type.GET,
+ return handleRequest(headers, null, ui, Request.Type.GET,
createResourceDefinition(null, m_clusterName));
}
@@ -80,6 +80,7 @@ public class ServiceService extends Base
* Handles: PUT /clusters/{clusterId}/services/{serviceId}
* Create a specific service.
*
+ * @param body http body
* @param headers http headers
* @param ui uri info
* @param serviceName service id
@@ -87,16 +88,17 @@ public class ServiceService extends Base
*/
@PUT
@Produces("text/plain")
- public Response createService(@Context HttpHeaders headers, @Context UriInfo ui,
+ public Response createService(String body, @Context HttpHeaders headers, @Context UriInfo ui,
@PathParam("serviceName") String serviceName) {
- return handleRequest(headers, ui, Request.Type.PUT, createResourceDefinition(serviceName, m_clusterName));
+ return handleRequest(headers, body, ui, Request.Type.PUT, createResourceDefinition(serviceName, m_clusterName));
}
/**
* Handles: POST /clusters/{clusterId}/services/{serviceId}
* Update a specific service.
*
+ * @param body http body
* @param headers http headers
* @param ui uri info
* @param serviceName service id
@@ -104,10 +106,10 @@ public class ServiceService extends Base
*/
@POST
@Produces("text/plain")
- public Response updateService(@Context HttpHeaders headers, @Context UriInfo ui,
+ public Response updateService(String body, @Context HttpHeaders headers, @Context UriInfo ui,
@PathParam("serviceName") String serviceName) {
- return handleRequest(headers, ui, Request.Type.POST, createResourceDefinition(serviceName, m_clusterName));
+ return handleRequest(headers, body, ui, Request.Type.POST, createResourceDefinition(serviceName, m_clusterName));
}
/**
@@ -124,7 +126,7 @@ public class ServiceService extends Base
public Response deleteService(@Context HttpHeaders headers, @Context UriInfo ui,
@PathParam("serviceName") String serviceName) {
- return handleRequest(headers, ui, Request.Type.DELETE, createResourceDefinition(serviceName, m_clusterName));
+ return handleRequest(headers, null, ui, Request.Type.DELETE, createResourceDefinition(serviceName, m_clusterName));
}
/**
Added: incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/services/UpdatePersistenceManager.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/services/UpdatePersistenceManager.java?rev=1395830&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/services/UpdatePersistenceManager.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/services/UpdatePersistenceManager.java Tue Oct 9 00:55:06 2012
@@ -0,0 +1,40 @@
+/**
+ * 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.ambari.api.services;
+
+
+import org.apache.ambari.api.resources.ResourceDefinition;
+import org.apache.ambari.server.AmbariException;
+
+
+/**
+ * Responsible for persisting the updating of a resource in the back end.
+ */
+public class UpdatePersistenceManager extends BasePersistenceManager {
+ @Override
+ public void persist(ResourceDefinition resource) {
+ try {
+ getClusterController().updateResources(resource.getType(), createControllerRequest(resource.getProperties()),
+ resource.getQuery().getPredicate());
+ } catch (AmbariException e) {
+ //todo: handle exception
+ throw new RuntimeException("Update of resource failed: " + e, e);
+ }
+ }
+}
Added: incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/services/parsers/JsonPropertyParser.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/services/parsers/JsonPropertyParser.java?rev=1395830&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/services/parsers/JsonPropertyParser.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/services/parsers/JsonPropertyParser.java Tue Oct 9 00:55:06 2012
@@ -0,0 +1,64 @@
+/**
+ * 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.ambari.api.services.parsers;
+
+import org.apache.ambari.api.controller.utilities.Properties;
+import org.apache.ambari.server.controller.spi.PropertyId;
+import org.codehaus.jackson.JsonNode;
+import org.codehaus.jackson.map.ObjectMapper;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+/**
+ * JSON parser which parses a JSON string into a map of properties and values.
+ */
+public class JsonPropertyParser implements RequestBodyParser {
+ //todo: change value type to String when it is supported in back end
+ private Map<PropertyId, Object> m_properties = new HashMap<PropertyId, Object>();
+
+ @Override
+ public Map<PropertyId, Object> parse(String s) {
+ ObjectMapper mapper = new ObjectMapper();
+
+ try {
+ processNode(mapper.readValue(s, JsonNode.class), "");
+ } catch (IOException e) {
+ throw new RuntimeException("Unable to parse json: " + e, e);
+ }
+
+ return m_properties;
+ }
+
+ private void processNode(JsonNode node, String path) {
+ Iterator<String> iter = node.getFieldNames();
+ String name;
+ while (iter.hasNext()) {
+ name = iter.next();
+ JsonNode child = node.get(name);
+ if (child.isContainerNode()) {
+ processNode(child, path.isEmpty() ? name : path + '.' + name);
+ } else {
+ m_properties.put(Properties.getPropertyId(name, path), child.asText());
+ }
+ }
+ }
+}
Added: incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/services/parsers/RequestBodyParser.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/services/parsers/RequestBodyParser.java?rev=1395830&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/services/parsers/RequestBodyParser.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/services/parsers/RequestBodyParser.java Tue Oct 9 00:55:06 2012
@@ -0,0 +1,38 @@
+/**
+ * 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.ambari.api.services.parsers;
+
+import org.apache.ambari.server.controller.spi.PropertyId;
+
+import java.util.Map;
+
+/**
+ * Parse the provided String into a map of properties and associated values.
+ */
+public interface RequestBodyParser {
+ /**
+ * Parse the provided string into a map of properties and values.
+ * The key contains both the category hierarchy and the property name.
+ *
+ * @param s the string body to be parsed
+ *
+ * @return a map of properties or an empty map if no properties exist
+ */
+ public Map<PropertyId, Object> parse(String s);
+}
Modified: incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/services/serializers/JsonSerializer.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/services/serializers/JsonSerializer.java?rev=1395830&r1=1395829&r2=1395830&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/services/serializers/JsonSerializer.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/services/serializers/JsonSerializer.java Tue Oct 9 00:55:06 2012
@@ -61,6 +61,7 @@ public class JsonSerializer implements R
m_generator.close();
return bytesOut.toString("UTF-8");
} catch (IOException e) {
+ //todo: exception handling
throw new RuntimeException("Unable to serialize to json: " + e, e);
}
}
Modified: incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/TestSuite.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/TestSuite.java?rev=1395830&r1=1395829&r2=1395830&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/TestSuite.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/TestSuite.java Tue Oct 9 00:55:06 2012
@@ -4,19 +4,17 @@ package org.apache.ambari.api;
* All unit tests.
*/
-import org.apache.ambari.api.handlers.DelegatingRequestHandlerTest;
-import org.apache.ambari.api.handlers.ReadHandlerTest;
-import org.apache.ambari.api.services.ClusterServiceTest;
-import org.apache.ambari.api.services.ComponentServiceTest;
-import org.apache.ambari.api.services.HostComponentServiceTest;
-import org.apache.ambari.api.services.HostServiceTest;
-import org.apache.ambari.api.services.ServiceServiceTest;
+import org.apache.ambari.api.handlers.*;
+import org.apache.ambari.api.services.*;
+import org.apache.ambari.api.services.parsers.JsonPropertyParserTest;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
@RunWith(Suite.class)
@Suite.SuiteClasses({ClusterServiceTest.class, HostServiceTest.class, ServiceServiceTest.class,
ComponentServiceTest.class, HostComponentServiceTest.class, DelegatingRequestHandlerTest.class,
- ReadHandlerTest.class})
+ ReadHandlerTest.class, /*QueryImplTest.class*/ JsonPropertyParserTest.class, CreateHandlerTest.class,
+ UpdateHandlerTest.class, DeleteHandlerTest.class, CreatePersistenceManagerTest.class,
+ UpdatePersistenceManagerTest.class})
public class TestSuite {
}
Added: incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/handlers/CreateHandlerTest.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/handlers/CreateHandlerTest.java?rev=1395830&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/handlers/CreateHandlerTest.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/handlers/CreateHandlerTest.java Tue Oct 9 00:55:06 2012
@@ -0,0 +1,61 @@
+/**
+ * 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.ambari.api.handlers;
+
+import org.apache.ambari.api.resources.ResourceDefinition;
+import org.apache.ambari.api.services.PersistenceManager;
+import org.apache.ambari.api.services.Request;
+import org.apache.ambari.server.controller.spi.PropertyId;
+import org.junit.Test;
+import static org.junit.Assert.assertNotNull;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.easymock.EasyMock.*;
+
+/**
+ * Unit tests for CreateHandler.
+ */
+public class CreateHandlerTest {
+
+ @Test
+ public void testHandleRequest() {
+ Request request = createMock(Request.class);
+ ResourceDefinition resource = createMock(ResourceDefinition.class);
+ PersistenceManager pm = createStrictMock(PersistenceManager.class);
+
+ Map<PropertyId, Object> resourceProperties = new HashMap<PropertyId, Object>();
+
+ // expectations
+ expect(request.getResourceDefinition()).andReturn(resource);
+ expect(request.getHttpBodyProperties()).andReturn(resourceProperties);
+ resource.setProperties(resourceProperties);
+ expect(request.getPersistenceManager()).andReturn(pm);
+ pm.persist(resource);
+
+ replay(request, resource, pm);
+
+ Object returnVal = new CreateHandler().handleRequest(request);
+ //todo: additional assertions on return value?
+ assertNotNull(returnVal);
+
+ verify(request, resource, pm);
+ }
+}
Added: incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/handlers/DeleteHandlerTest.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/handlers/DeleteHandlerTest.java?rev=1395830&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/handlers/DeleteHandlerTest.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/handlers/DeleteHandlerTest.java Tue Oct 9 00:55:06 2012
@@ -0,0 +1,61 @@
+/**
+ * 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.ambari.api.handlers;
+
+import org.apache.ambari.api.resources.ResourceDefinition;
+import org.apache.ambari.api.services.PersistenceManager;
+import org.apache.ambari.api.services.Request;
+import org.apache.ambari.server.controller.spi.PropertyId;
+import org.junit.Test;
+import static org.junit.Assert.assertNotNull;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.easymock.EasyMock.*;
+
+/**
+ * Unit tests for DeleteHandler.
+ */
+public class DeleteHandlerTest {
+
+ @Test
+ public void testHandleRequest() {
+ Request request = createMock(Request.class);
+ ResourceDefinition resource = createMock(ResourceDefinition.class);
+ PersistenceManager pm = createStrictMock(PersistenceManager.class);
+
+ Map<PropertyId, Object> resourceProperties = new HashMap<PropertyId, Object>();
+
+ // expectations
+ expect(request.getResourceDefinition()).andReturn(resource);
+ expect(request.getHttpBodyProperties()).andReturn(resourceProperties);
+ resource.setProperties(resourceProperties);
+ expect(request.getPersistenceManager()).andReturn(pm);
+ pm.persist(resource);
+
+ replay(request, resource, pm);
+
+ Object returnVal = new DeleteHandler().handleRequest(request);
+ //todo: additional assertions on return value?
+ assertNotNull(returnVal);
+
+ verify(request, resource, pm);
+ }
+}
\ No newline at end of file
Modified: incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/handlers/ReadHandlerTest.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/handlers/ReadHandlerTest.java?rev=1395830&r1=1395829&r2=1395830&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/handlers/ReadHandlerTest.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/handlers/ReadHandlerTest.java Tue Oct 9 00:55:06 2012
@@ -1,7 +1,25 @@
+/**
+ * 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.ambari.api.handlers;
import org.apache.ambari.api.query.Query;
-import org.apache.ambari.api.resource.ResourceDefinition;
+import org.apache.ambari.api.resources.ResourceDefinition;
import org.apache.ambari.api.services.Request;
import org.apache.ambari.api.services.Result;
import org.junit.Test;
@@ -14,11 +32,7 @@ import static org.easymock.EasyMock.*;
import static org.junit.Assert.assertSame;
/**
- * Created with IntelliJ IDEA.
- * User: john
- * Date: 9/12/12
- * Time: 12:45 PM
- * To change this template use File | Settings | File Templates.
+ * Unit tests for ReadHandler.
*/
public class ReadHandlerTest {
Added: incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/handlers/UpdateHandlerTest.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/handlers/UpdateHandlerTest.java?rev=1395830&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/handlers/UpdateHandlerTest.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/handlers/UpdateHandlerTest.java Tue Oct 9 00:55:06 2012
@@ -0,0 +1,61 @@
+/**
+ * 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.ambari.api.handlers;
+
+import org.apache.ambari.api.resources.ResourceDefinition;
+import org.apache.ambari.api.services.PersistenceManager;
+import org.apache.ambari.api.services.Request;
+import org.apache.ambari.server.controller.spi.PropertyId;
+import org.junit.Test;
+import static org.junit.Assert.assertNotNull;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.easymock.EasyMock.*;
+
+/**
+ * Unit tests for UpdateHandler.
+ */
+public class UpdateHandlerTest {
+
+ @Test
+ public void testHandleRequest() {
+ Request request = createMock(Request.class);
+ ResourceDefinition resource = createMock(ResourceDefinition.class);
+ PersistenceManager pm = createStrictMock(PersistenceManager.class);
+
+ Map<PropertyId, Object> resourceProperties = new HashMap<PropertyId, Object>();
+
+ // expectations
+ expect(request.getResourceDefinition()).andReturn(resource);
+ expect(request.getHttpBodyProperties()).andReturn(resourceProperties);
+ resource.setProperties(resourceProperties);
+ expect(request.getPersistenceManager()).andReturn(pm);
+ pm.persist(resource);
+
+ replay(request, resource, pm);
+
+ Object returnVal = new UpdateHandler().handleRequest(request);
+ //todo: additional assertions on return value?
+ assertNotNull(returnVal);
+
+ verify(request, resource, pm);
+ }
+}
\ No newline at end of file
Modified: incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/query/QueryImplTest.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/query/QueryImplTest.java?rev=1395830&r1=1395829&r2=1395830&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/query/QueryImplTest.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/query/QueryImplTest.java Tue Oct 9 00:55:06 2012
@@ -1,28 +1,26 @@
package org.apache.ambari.api.query;
-import org.apache.ambari.api.controller.internal.PropertyIdImpl;
-import org.apache.ambari.server.controller.predicate.EqualsPredicate;
-import org.apache.ambari.api.resource.ResourceDefinition;
-import org.apache.ambari.api.services.Result;
-import org.apache.ambari.server.controller.spi.*;
-import org.apache.ambari.api.controller.utilities.PredicateBuilder;
-import org.junit.After;
-import org.junit.Test;
-
-import java.util.*;
+//import org.apache.ambari.api.controller.internal.PropertyIdImpl;
+//import org.apache.ambari.api.controller.utilities.PredicateBuilder;
+//import org.apache.ambari.api.resources.ResourceDefinition;
+//import org.apache.ambari.api.services.Request;
+//import org.apache.ambari.api.services.Result;
+//import org.apache.ambari.server.controller.spi.ClusterController;
+//import org.apache.ambari.server.controller.spi.Predicate;
+//import org.apache.ambari.server.controller.spi.Resource;
+//import org.apache.ambari.server.controller.spi.Schema;
+//import org.junit.Test;
+//
+//import java.util.*;
+//
+//
+//import static org.easymock.EasyMock.*;
+//
+//import static org.junit.Assert.assertEquals;
+//import static org.junit.Assert.assertSame;
-import static org.easymock.EasyMock.*;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertSame;
-/**
- * Created with IntelliJ IDEA.
- * User: john
- * Date: 9/12/12
- * Time: 12:55 PM
- * To change this template use File | Settings | File Templates.
- */
public class QueryImplTest {
// ClusterController m_controller = createStrictMock(ClusterController.class);
Modified: incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/services/ClusterServiceTest.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/services/ClusterServiceTest.java?rev=1395830&r1=1395829&r2=1395830&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/services/ClusterServiceTest.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/services/ClusterServiceTest.java Tue Oct 9 00:55:06 2012
@@ -1,7 +1,7 @@
package org.apache.ambari.api.services;
import org.apache.ambari.api.handlers.RequestHandler;
-import org.apache.ambari.api.resource.ResourceDefinition;
+import org.apache.ambari.api.resources.ResourceDefinition;
import org.apache.ambari.api.services.serializers.ResultSerializer;
import org.junit.Test;
@@ -40,7 +40,7 @@ public class ClusterServiceTest {
String clusterName = "clusterName";
// expectations
- expect(requestFactory.createRequest(eq(httpHeaders), eq(uriInfo), eq(Request.Type.GET),
+ expect(requestFactory.createRequest(eq(httpHeaders), isNull(String.class), eq(uriInfo), eq(Request.Type.GET),
eq(resourceDef))).andReturn(request);
expect(requestHandler.handleRequest(request)).andReturn(result);
@@ -75,7 +75,7 @@ public class ClusterServiceTest {
UriInfo uriInfo = createNiceMock(UriInfo.class);
// expectations
- expect(requestFactory.createRequest(eq(httpHeaders), eq(uriInfo), eq(Request.Type.GET),
+ expect(requestFactory.createRequest(eq(httpHeaders), isNull(String.class), eq(uriInfo), eq(Request.Type.GET),
eq(resourceDef))).andReturn(request);
expect(requestHandler.handleRequest(request)).andReturn(result);
@@ -111,7 +111,7 @@ public class ClusterServiceTest {
String clusterName = "clusterName";
// expectations
- expect(requestFactory.createRequest(eq(httpHeaders), eq(uriInfo), eq(Request.Type.PUT),
+ expect(requestFactory.createRequest(eq(httpHeaders), eq("body"), eq(uriInfo), eq(Request.Type.PUT),
eq(resourceDef))).andReturn(request);
expect(requestHandler.handleRequest(request)).andReturn(result);
@@ -124,7 +124,7 @@ public class ClusterServiceTest {
//test
ClusterService clusterService = new TestClusterService(resourceDef, clusterName, requestFactory, responseFactory, requestHandler);
- assertSame(response, clusterService.createCluster(httpHeaders, uriInfo, clusterName));
+ assertSame(response, clusterService.createCluster("body", httpHeaders, uriInfo, clusterName));
verify(resourceDef, resultSerializer, requestFactory, responseFactory, request, requestHandler,
result, response, httpHeaders, uriInfo);
@@ -147,7 +147,7 @@ public class ClusterServiceTest {
String clusterName = "clusterName";
// expectations
- expect(requestFactory.createRequest(eq(httpHeaders), eq(uriInfo), eq(Request.Type.POST),
+ expect(requestFactory.createRequest(eq(httpHeaders), eq("body"), eq(uriInfo), eq(Request.Type.POST),
eq(resourceDef))).andReturn(request);
expect(requestHandler.handleRequest(request)).andReturn(result);
@@ -160,7 +160,7 @@ public class ClusterServiceTest {
//test
ClusterService clusterService = new TestClusterService(resourceDef, clusterName, requestFactory, responseFactory, requestHandler);
- assertSame(response, clusterService.updateCluster(httpHeaders, uriInfo, clusterName));
+ assertSame(response, clusterService.updateCluster("body", httpHeaders, uriInfo, clusterName));
verify(resourceDef, resultSerializer, requestFactory, responseFactory, request, requestHandler,
result, response, httpHeaders, uriInfo);
@@ -183,7 +183,7 @@ public class ClusterServiceTest {
String clusterName = "clusterName";
// expectations
- expect(requestFactory.createRequest(eq(httpHeaders), eq(uriInfo), eq(Request.Type.DELETE),
+ expect(requestFactory.createRequest(eq(httpHeaders), isNull(String.class), eq(uriInfo), eq(Request.Type.DELETE),
eq(resourceDef))).andReturn(request);
expect(requestHandler.handleRequest(request)).andReturn(result);
Modified: incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/services/ComponentServiceTest.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/services/ComponentServiceTest.java?rev=1395830&r1=1395829&r2=1395830&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/services/ComponentServiceTest.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/services/ComponentServiceTest.java Tue Oct 9 00:55:06 2012
@@ -2,7 +2,7 @@ package org.apache.ambari.api.services;
import org.apache.ambari.api.handlers.RequestHandler;
-import org.apache.ambari.api.resource.ResourceDefinition;
+import org.apache.ambari.api.resources.ResourceDefinition;
import org.apache.ambari.api.services.serializers.ResultSerializer;
import org.junit.Test;
@@ -44,7 +44,7 @@ public class ComponentServiceTest {
String componentName = "componentName";
// expectations
- expect(requestFactory.createRequest(eq(httpHeaders), eq(uriInfo), eq(Request.Type.GET),
+ expect(requestFactory.createRequest(eq(httpHeaders), isNull(String.class), eq(uriInfo), eq(Request.Type.GET),
eq(resourceDef))).andReturn(request);
expect(requestHandler.handleRequest(request)).andReturn(result);
@@ -84,7 +84,7 @@ public class ComponentServiceTest {
String serviceName = "serviceName";
// expectations
- expect(requestFactory.createRequest(eq(httpHeaders), eq(uriInfo), eq(Request.Type.GET),
+ expect(requestFactory.createRequest(eq(httpHeaders), isNull(String.class), eq(uriInfo), eq(Request.Type.GET),
eq(resourceDef))).andReturn(request);
expect(requestHandler.handleRequest(request)).andReturn(result);
@@ -103,6 +103,128 @@ public class ComponentServiceTest {
result, response, httpHeaders, uriInfo);
}
+ @Test
+ public void testPutComponent() {
+ ResourceDefinition resourceDef = createStrictMock(ResourceDefinition.class);
+ ResultSerializer resultSerializer = createStrictMock(ResultSerializer.class);
+ Object serializedResult = new Object();
+ RequestFactory requestFactory = createStrictMock(RequestFactory.class);
+ ResponseFactory responseFactory = createStrictMock(ResponseFactory.class);
+ Request request = createNiceMock(Request.class);
+ RequestHandler requestHandler = createStrictMock(RequestHandler.class);
+ Result result = createStrictMock(Result.class);
+ Response response = createStrictMock(Response.class);
+ HttpHeaders httpHeaders = createNiceMock(HttpHeaders.class);
+ UriInfo uriInfo = createNiceMock(UriInfo.class);
+
+ String clusterName = "clusterName";
+ String serviceName = "serviceName";
+ String componentName = "componentName";
+
+ // expectations
+ expect(requestFactory.createRequest(eq(httpHeaders), eq("body"), eq(uriInfo), eq(Request.Type.PUT),
+ eq(resourceDef))).andReturn(request);
+
+ expect(requestHandler.handleRequest(request)).andReturn(result);
+ expect(request.getResultSerializer()).andReturn(resultSerializer);
+ expect(resultSerializer.serialize(result, uriInfo)).andReturn(serializedResult);
+
+ expect(responseFactory.createResponse(serializedResult)).andReturn(response);
+
+ replay(resourceDef, resultSerializer, requestFactory, responseFactory, request, requestHandler,
+ result, response, httpHeaders, uriInfo);
+
+ //test
+ ComponentService componentService = new TestComponentService(resourceDef, clusterName, serviceName, componentName,
+ requestFactory, responseFactory, requestHandler);
+ assertSame(response, componentService.createComponent("body", httpHeaders, uriInfo, componentName));
+
+ verify(resourceDef, resultSerializer, requestFactory, responseFactory, request, requestHandler,
+ result, response, httpHeaders, uriInfo);
+ }
+
+ @Test
+ public void testPostComponent() {
+ ResourceDefinition resourceDef = createStrictMock(ResourceDefinition.class);
+ ResultSerializer resultSerializer = createStrictMock(ResultSerializer.class);
+ Object serializedResult = new Object();
+ RequestFactory requestFactory = createStrictMock(RequestFactory.class);
+ ResponseFactory responseFactory = createStrictMock(ResponseFactory.class);
+ Request request = createNiceMock(Request.class);
+ RequestHandler requestHandler = createStrictMock(RequestHandler.class);
+ Result result = createStrictMock(Result.class);
+ Response response = createStrictMock(Response.class);
+ HttpHeaders httpHeaders = createNiceMock(HttpHeaders.class);
+ UriInfo uriInfo = createNiceMock(UriInfo.class);
+
+ String clusterName = "clusterName";
+ String serviceName = "serviceName";
+ String componentName = "componentName";
+
+ // expectations
+ expect(requestFactory.createRequest(eq(httpHeaders), eq("body"), eq(uriInfo), eq(Request.Type.POST),
+ eq(resourceDef))).andReturn(request);
+
+ expect(requestHandler.handleRequest(request)).andReturn(result);
+ expect(request.getResultSerializer()).andReturn(resultSerializer);
+ expect(resultSerializer.serialize(result, uriInfo)).andReturn(serializedResult);
+
+ expect(responseFactory.createResponse(serializedResult)).andReturn(response);
+
+ replay(resourceDef, resultSerializer, requestFactory, responseFactory, request, requestHandler,
+ result, response, httpHeaders, uriInfo);
+
+ //test
+ ComponentService componentService = new TestComponentService(resourceDef, clusterName, serviceName, componentName,
+ requestFactory, responseFactory, requestHandler);
+ assertSame(response, componentService.updateComponent("body", httpHeaders, uriInfo, componentName));
+
+ verify(resourceDef, resultSerializer, requestFactory, responseFactory, request, requestHandler,
+ result, response, httpHeaders, uriInfo);
+ }
+
+ @Test
+ public void testDeleteComponent() {
+ ResourceDefinition resourceDef = createStrictMock(ResourceDefinition.class);
+ ResultSerializer resultSerializer = createStrictMock(ResultSerializer.class);
+ Object serializedResult = new Object();
+ RequestFactory requestFactory = createStrictMock(RequestFactory.class);
+ ResponseFactory responseFactory = createStrictMock(ResponseFactory.class);
+ Request request = createNiceMock(Request.class);
+ RequestHandler requestHandler = createStrictMock(RequestHandler.class);
+ Result result = createStrictMock(Result.class);
+ Response response = createStrictMock(Response.class);
+ HttpHeaders httpHeaders = createNiceMock(HttpHeaders.class);
+ UriInfo uriInfo = createNiceMock(UriInfo.class);
+
+ String clusterName = "clusterName";
+ String serviceName = "serviceName";
+ String componentName = "componentName";
+
+ // expectations
+ expect(requestFactory.createRequest(eq(httpHeaders), isNull(String.class), eq(uriInfo), eq(Request.Type.DELETE),
+ eq(resourceDef))).andReturn(request);
+
+ expect(requestHandler.handleRequest(request)).andReturn(result);
+ expect(request.getResultSerializer()).andReturn(resultSerializer);
+ expect(resultSerializer.serialize(result, uriInfo)).andReturn(serializedResult);
+
+ expect(responseFactory.createResponse(serializedResult)).andReturn(response);
+
+ replay(resourceDef, resultSerializer, requestFactory, responseFactory, request, requestHandler,
+ result, response, httpHeaders, uriInfo);
+
+ //test
+ ComponentService componentService = new TestComponentService(resourceDef, clusterName, serviceName, componentName,
+ requestFactory, responseFactory, requestHandler);
+ assertSame(response, componentService.deleteComponent(httpHeaders, uriInfo, componentName));
+
+ verify(resourceDef, resultSerializer, requestFactory, responseFactory, request, requestHandler,
+ result, response, httpHeaders, uriInfo);
+ }
+
+
+
private class TestComponentService extends ComponentService {
private RequestFactory m_requestFactory;
private ResponseFactory m_responseFactory;
Added: incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/services/CreatePersistenceManagerTest.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/services/CreatePersistenceManagerTest.java?rev=1395830&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/services/CreatePersistenceManagerTest.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/services/CreatePersistenceManagerTest.java Tue Oct 9 00:55:06 2012
@@ -0,0 +1,105 @@
+/**
+ * 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.ambari.api.services;
+
+import org.apache.ambari.api.controller.utilities.Properties;
+import org.apache.ambari.api.resources.ResourceDefinition;
+import org.apache.ambari.server.controller.spi.ClusterController;
+import org.apache.ambari.server.controller.spi.PropertyId;
+import org.apache.ambari.server.controller.spi.Resource;
+import org.apache.ambari.server.controller.spi.Schema;
+import org.junit.Test;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.junit.Assert.*;
+
+import static org.easymock.EasyMock.*;
+
+/**
+ * Unit tests for CreatePersistenceManager.
+ */
+public class CreatePersistenceManagerTest {
+ @Test
+ public void testPersist() throws Exception {
+ ResourceDefinition resource = createMock(ResourceDefinition.class);
+ ClusterController controller = createMock(ClusterController.class);
+ Schema schema = createMock(Schema.class);
+ PropertyId clusterId = createStrictMock(PropertyId.class);
+ PropertyId serviceId = createStrictMock(PropertyId.class);
+ org.apache.ambari.server.controller.spi.Request serverRequest =
+ createStrictMock(org.apache.ambari.server.controller.spi.Request.class);
+
+ Map<Resource.Type, String> mapResourceIds = new HashMap<Resource.Type, String>();
+ mapResourceIds.put(Resource.Type.Cluster, "clusterId");
+ mapResourceIds.put(Resource.Type.Service, "serviceId");
+
+ Map<PropertyId, Object> mapProperties = new HashMap<PropertyId, Object>();
+ mapProperties.put(clusterId, "clusterId");
+ mapProperties.put(serviceId, "serviceId");
+ mapProperties.put(Properties.getPropertyId("bar", "foo"), "value");
+
+ //expectations
+ expect(resource.getResourceIds()).andReturn(mapResourceIds);
+ expect(resource.getType()).andReturn(Resource.Type.Component);
+ expect(controller.getSchema(Resource.Type.Component)).andReturn(schema);
+ expect(schema.getKeyPropertyId(Resource.Type.Cluster)).andReturn(clusterId);
+ resource.setProperty(clusterId, "clusterId");
+ expect(schema.getKeyPropertyId(Resource.Type.Service)).andReturn(serviceId);
+ resource.setProperty(serviceId, "serviceId");
+ expect(resource.getProperties()).andReturn(mapProperties);
+
+ controller.createResources(Resource.Type.Component, serverRequest);
+
+ replay(resource, controller, schema, clusterId, serviceId, serverRequest);
+
+ new TestCreatePersistenceManager(controller, mapProperties, serverRequest).persist(resource);
+
+ verify(resource, controller, schema, clusterId, serviceId, serverRequest);
+
+ }
+
+ private class TestCreatePersistenceManager extends CreatePersistenceManager {
+
+ private ClusterController m_controller;
+ private org.apache.ambari.server.controller.spi.Request m_request;
+ private Map<PropertyId, Object> m_mapProperties;
+
+ private TestCreatePersistenceManager(ClusterController controller,
+ Map<PropertyId, Object> mapProperties,
+ org.apache.ambari.server.controller.spi.Request controllerRequest) {
+ m_controller = controller;
+ m_mapProperties = mapProperties;
+ m_request = controllerRequest;
+ }
+
+ @Override
+ protected ClusterController getClusterController() {
+ return m_controller;
+ }
+
+ @Override
+ protected org.apache.ambari.server.controller.spi.Request createControllerRequest(Map<PropertyId, Object> properties) {
+ assertEquals(m_mapProperties, properties);
+ return m_request;
+ }
+ }
+
+}
Added: incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/services/DeletePersistenceManagerTest.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/services/DeletePersistenceManagerTest.java?rev=1395830&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/services/DeletePersistenceManagerTest.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/services/DeletePersistenceManagerTest.java Tue Oct 9 00:55:06 2012
@@ -0,0 +1,71 @@
+/**
+ * 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.ambari.api.services;
+
+
+import org.apache.ambari.api.query.Query;
+import org.apache.ambari.api.resources.ResourceDefinition;
+import org.apache.ambari.server.controller.spi.*;
+import org.junit.Test;
+
+import static org.easymock.EasyMock.*;
+
+/**
+ * Unit tests for UpdatePersistenceManager.
+ */
+public class DeletePersistenceManagerTest {
+ @Test
+ public void testPersist() throws Exception {
+ ResourceDefinition resource = createMock(ResourceDefinition.class);
+ ClusterController controller = createMock(ClusterController.class);
+ Schema schema = createMock(Schema.class);
+ Query query = createMock(Query.class);
+ Predicate predicate = createMock(Predicate.class);
+
+
+ //expectations
+ expect(resource.getType()).andReturn(Resource.Type.Component);
+ expect(resource.getQuery()).andReturn(query);
+ expect(query.getPredicate()).andReturn(predicate);
+
+ controller.deleteResources(Resource.Type.Component, predicate);
+
+ replay(resource, controller, schema, query, predicate);
+
+ new TestDeletePersistenceManager(controller).persist(resource);
+
+ verify(resource, controller, schema, query, predicate);
+ }
+
+
+ private class TestDeletePersistenceManager extends DeletePersistenceManager {
+
+ private ClusterController m_controller;
+
+ private TestDeletePersistenceManager(ClusterController controller) {
+ m_controller = controller;
+ }
+
+ @Override
+ protected ClusterController getClusterController() {
+ return m_controller;
+ }
+ }
+
+}
Modified: incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/services/HostComponentServiceTest.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/services/HostComponentServiceTest.java?rev=1395830&r1=1395829&r2=1395830&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/services/HostComponentServiceTest.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/services/HostComponentServiceTest.java Tue Oct 9 00:55:06 2012
@@ -1,7 +1,7 @@
package org.apache.ambari.api.services;
import org.apache.ambari.api.handlers.RequestHandler;
-import org.apache.ambari.api.resource.ResourceDefinition;
+import org.apache.ambari.api.resources.ResourceDefinition;
import org.apache.ambari.api.services.serializers.ResultSerializer;
import org.junit.Test;
@@ -42,7 +42,7 @@ public class HostComponentServiceTest {
String hostComponentName = "hostComponentName";
// expectations
- expect(requestFactory.createRequest(eq(httpHeaders), eq(uriInfo), eq(Request.Type.GET),
+ expect(requestFactory.createRequest(eq(httpHeaders), isNull(String.class), eq(uriInfo), eq(Request.Type.GET),
eq(resourceDef))).andReturn(request);
expect(requestHandler.handleRequest(request)).andReturn(result);
@@ -81,7 +81,7 @@ public class HostComponentServiceTest {
String hostName = "hostName";
// expectations
- expect(requestFactory.createRequest(eq(httpHeaders), eq(uriInfo), eq(Request.Type.GET),
+ expect(requestFactory.createRequest(eq(httpHeaders), isNull(String.class), eq(uriInfo), eq(Request.Type.GET),
eq(resourceDef))).andReturn(request);
expect(requestHandler.handleRequest(request)).andReturn(result);
@@ -101,6 +101,126 @@ public class HostComponentServiceTest {
result, response, httpHeaders, uriInfo);
}
+ @Test
+ public void testPutHostComponent() {
+ ResourceDefinition resourceDef = createStrictMock(ResourceDefinition.class);
+ ResultSerializer resultSerializer = createStrictMock(ResultSerializer.class);
+ Object serializedResult = new Object();
+ RequestFactory requestFactory = createStrictMock(RequestFactory.class);
+ ResponseFactory responseFactory = createStrictMock(ResponseFactory.class);
+ Request request = createNiceMock(Request.class);
+ RequestHandler requestHandler = createStrictMock(RequestHandler.class);
+ Result result = createStrictMock(Result.class);
+ Response response = createStrictMock(Response.class);
+
+ HttpHeaders httpHeaders = createNiceMock(HttpHeaders.class);
+ UriInfo uriInfo = createNiceMock(UriInfo.class);
+
+ String clusterName = "clusterName";
+ String hostName = "hostName";
+ String hostComponentName = "hostComponentName";
+
+ // expectations
+ expect(requestFactory.createRequest(eq(httpHeaders), eq("body"), eq(uriInfo), eq(Request.Type.PUT),
+ eq(resourceDef))).andReturn(request);
+
+ expect(requestHandler.handleRequest(request)).andReturn(result);
+ expect(request.getResultSerializer()).andReturn(resultSerializer);
+ expect(resultSerializer.serialize(result, uriInfo)).andReturn(serializedResult);
+ expect(responseFactory.createResponse(serializedResult)).andReturn(response);
+
+ replay(resourceDef, resultSerializer, requestFactory, responseFactory, request, requestHandler,
+ result, response, httpHeaders, uriInfo);
+
+ //test
+ HostComponentService hostComponentService = new TestHostComponentService(resourceDef, clusterName, hostName, hostComponentName,
+ requestFactory, responseFactory, requestHandler);
+ assertSame(response, hostComponentService.createHostComponent("body", httpHeaders, uriInfo, hostComponentName));
+
+ verify(resourceDef, resultSerializer, requestFactory, responseFactory, request, requestHandler,
+ result, response, httpHeaders, uriInfo);
+ }
+
+ @Test
+ public void testPostHostComponent() {
+ ResourceDefinition resourceDef = createStrictMock(ResourceDefinition.class);
+ ResultSerializer resultSerializer = createStrictMock(ResultSerializer.class);
+ Object serializedResult = new Object();
+ RequestFactory requestFactory = createStrictMock(RequestFactory.class);
+ ResponseFactory responseFactory = createStrictMock(ResponseFactory.class);
+ Request request = createNiceMock(Request.class);
+ RequestHandler requestHandler = createStrictMock(RequestHandler.class);
+ Result result = createStrictMock(Result.class);
+ Response response = createStrictMock(Response.class);
+
+ HttpHeaders httpHeaders = createNiceMock(HttpHeaders.class);
+ UriInfo uriInfo = createNiceMock(UriInfo.class);
+
+ String clusterName = "clusterName";
+ String hostName = "hostName";
+ String hostComponentName = "hostComponentName";
+
+ // expectations
+ expect(requestFactory.createRequest(eq(httpHeaders), eq("body"), eq(uriInfo), eq(Request.Type.POST),
+ eq(resourceDef))).andReturn(request);
+
+ expect(requestHandler.handleRequest(request)).andReturn(result);
+ expect(request.getResultSerializer()).andReturn(resultSerializer);
+ expect(resultSerializer.serialize(result, uriInfo)).andReturn(serializedResult);
+ expect(responseFactory.createResponse(serializedResult)).andReturn(response);
+
+ replay(resourceDef, resultSerializer, requestFactory, responseFactory, request, requestHandler,
+ result, response, httpHeaders, uriInfo);
+
+ //test
+ HostComponentService hostComponentService = new TestHostComponentService(resourceDef, clusterName, hostName, hostComponentName,
+ requestFactory, responseFactory, requestHandler);
+ assertSame(response, hostComponentService.updateHostComponent("body", httpHeaders, uriInfo, hostComponentName));
+
+ verify(resourceDef, resultSerializer, requestFactory, responseFactory, request, requestHandler,
+ result, response, httpHeaders, uriInfo);
+ }
+
+ @Test
+ public void testDeleteHostComponent() {
+ ResourceDefinition resourceDef = createStrictMock(ResourceDefinition.class);
+ ResultSerializer resultSerializer = createStrictMock(ResultSerializer.class);
+ Object serializedResult = new Object();
+ RequestFactory requestFactory = createStrictMock(RequestFactory.class);
+ ResponseFactory responseFactory = createStrictMock(ResponseFactory.class);
+ Request request = createNiceMock(Request.class);
+ RequestHandler requestHandler = createStrictMock(RequestHandler.class);
+ Result result = createStrictMock(Result.class);
+ Response response = createStrictMock(Response.class);
+
+ HttpHeaders httpHeaders = createNiceMock(HttpHeaders.class);
+ UriInfo uriInfo = createNiceMock(UriInfo.class);
+
+ String clusterName = "clusterName";
+ String hostName = "hostName";
+ String hostComponentName = "hostComponentName";
+
+ // expectations
+ expect(requestFactory.createRequest(eq(httpHeaders), isNull(String.class), eq(uriInfo), eq(Request.Type.DELETE),
+ eq(resourceDef))).andReturn(request);
+
+ expect(requestHandler.handleRequest(request)).andReturn(result);
+ expect(request.getResultSerializer()).andReturn(resultSerializer);
+ expect(resultSerializer.serialize(result, uriInfo)).andReturn(serializedResult);
+ expect(responseFactory.createResponse(serializedResult)).andReturn(response);
+
+ replay(resourceDef, resultSerializer, requestFactory, responseFactory, request, requestHandler,
+ result, response, httpHeaders, uriInfo);
+
+ //test
+ HostComponentService hostComponentService = new TestHostComponentService(resourceDef, clusterName, hostName, hostComponentName,
+ requestFactory, responseFactory, requestHandler);
+ assertSame(response, hostComponentService.deleteHostComponent(httpHeaders, uriInfo, hostComponentName));
+
+ verify(resourceDef, resultSerializer, requestFactory, responseFactory, request, requestHandler,
+ result, response, httpHeaders, uriInfo);
+ }
+
private class TestHostComponentService extends HostComponentService {
private RequestFactory m_requestFactory;
private ResponseFactory m_responseFactory;
Modified: incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/services/HostServiceTest.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/services/HostServiceTest.java?rev=1395830&r1=1395829&r2=1395830&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/services/HostServiceTest.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/services/HostServiceTest.java Tue Oct 9 00:55:06 2012
@@ -2,7 +2,7 @@ package org.apache.ambari.api.services;
import org.apache.ambari.api.handlers.RequestHandler;
-import org.apache.ambari.api.resource.ResourceDefinition;
+import org.apache.ambari.api.resources.ResourceDefinition;
import org.apache.ambari.api.services.serializers.ResultSerializer;
import org.junit.Test;
@@ -42,7 +42,7 @@ public class HostServiceTest {
String hostName = "hostName";
// expectations
- expect(requestFactory.createRequest(eq(httpHeaders), eq(uriInfo), eq(Request.Type.GET),
+ expect(requestFactory.createRequest(eq(httpHeaders), isNull(String.class), eq(uriInfo), eq(Request.Type.GET),
eq(resourceDef))).andReturn(request);
expect(requestHandler.handleRequest(request)).andReturn(result);
@@ -79,7 +79,7 @@ public class HostServiceTest {
String clusterName = "clusterName";
// expectations
- expect(requestFactory.createRequest(eq(httpHeaders), eq(uriInfo), eq(Request.Type.GET),
+ expect(requestFactory.createRequest(eq(httpHeaders), isNull(String.class), eq(uriInfo), eq(Request.Type.GET),
eq(resourceDef))).andReturn(request);
expect(requestHandler.handleRequest(request)).andReturn(result);
@@ -98,6 +98,121 @@ public class HostServiceTest {
result, response, httpHeaders, uriInfo);
}
+ @Test
+ public void testCreateHost() {
+ ResourceDefinition resourceDef = createStrictMock(ResourceDefinition.class);
+ ResultSerializer resultSerializer = createStrictMock(ResultSerializer.class);
+ Object serializedResult = new Object();
+ RequestFactory requestFactory = createStrictMock(RequestFactory.class);
+ ResponseFactory responseFactory = createStrictMock(ResponseFactory.class);
+ Request request = createNiceMock(Request.class);
+ RequestHandler requestHandler = createStrictMock(RequestHandler.class);
+ Result result = createStrictMock(Result.class);
+ Response response = createStrictMock(Response.class);
+
+ HttpHeaders httpHeaders = createNiceMock(HttpHeaders.class);
+ UriInfo uriInfo = createNiceMock(UriInfo.class);
+
+ String clusterName = "clusterName";
+ String hostName = "hostName";
+
+ // expectations
+ expect(requestFactory.createRequest(eq(httpHeaders), eq("body"), eq(uriInfo), eq(Request.Type.PUT),
+ eq(resourceDef))).andReturn(request);
+
+ expect(requestHandler.handleRequest(request)).andReturn(result);
+ expect(request.getResultSerializer()).andReturn(resultSerializer);
+ expect(resultSerializer.serialize(result, uriInfo)).andReturn(serializedResult);
+ expect(responseFactory.createResponse(serializedResult)).andReturn(response);
+
+ replay(resourceDef, resultSerializer, requestFactory, responseFactory, request, requestHandler,
+ result, response, httpHeaders, uriInfo);
+
+ //test
+ HostService hostService = new TestHostService(resourceDef, clusterName, hostName, requestFactory, responseFactory, requestHandler);
+ assertSame(response, hostService.createHost("body", httpHeaders, uriInfo, hostName));
+
+ verify(resourceDef, resultSerializer, requestFactory, responseFactory, request, requestHandler,
+ result, response, httpHeaders, uriInfo);
+ }
+
+ @Test
+ public void testUpdateHost() {
+ ResourceDefinition resourceDef = createStrictMock(ResourceDefinition.class);
+ ResultSerializer resultSerializer = createStrictMock(ResultSerializer.class);
+ Object serializedResult = new Object();
+ RequestFactory requestFactory = createStrictMock(RequestFactory.class);
+ ResponseFactory responseFactory = createStrictMock(ResponseFactory.class);
+ Request request = createNiceMock(Request.class);
+ RequestHandler requestHandler = createStrictMock(RequestHandler.class);
+ Result result = createStrictMock(Result.class);
+ Response response = createStrictMock(Response.class);
+
+ HttpHeaders httpHeaders = createNiceMock(HttpHeaders.class);
+ UriInfo uriInfo = createNiceMock(UriInfo.class);
+
+ String clusterName = "clusterName";
+ String hostName = "hostName";
+
+ // expectations
+ expect(requestFactory.createRequest(eq(httpHeaders), eq("body"), eq(uriInfo), eq(Request.Type.POST),
+ eq(resourceDef))).andReturn(request);
+
+ expect(requestHandler.handleRequest(request)).andReturn(result);
+ expect(request.getResultSerializer()).andReturn(resultSerializer);
+ expect(resultSerializer.serialize(result, uriInfo)).andReturn(serializedResult);
+ expect(responseFactory.createResponse(serializedResult)).andReturn(response);
+
+ replay(resourceDef, resultSerializer, requestFactory, responseFactory, request, requestHandler,
+ result, response, httpHeaders, uriInfo);
+
+ //test
+ HostService hostService = new TestHostService(resourceDef, clusterName, hostName, requestFactory, responseFactory, requestHandler);
+ assertSame(response, hostService.updateHost("body", httpHeaders, uriInfo, hostName));
+
+ verify(resourceDef, resultSerializer, requestFactory, responseFactory, request, requestHandler,
+ result, response, httpHeaders, uriInfo);
+ }
+
+ @Test
+ public void testDeleteHost() {
+ ResourceDefinition resourceDef = createStrictMock(ResourceDefinition.class);
+ ResultSerializer resultSerializer = createStrictMock(ResultSerializer.class);
+ Object serializedResult = new Object();
+ RequestFactory requestFactory = createStrictMock(RequestFactory.class);
+ ResponseFactory responseFactory = createStrictMock(ResponseFactory.class);
+ Request request = createNiceMock(Request.class);
+ RequestHandler requestHandler = createStrictMock(RequestHandler.class);
+ Result result = createStrictMock(Result.class);
+ Response response = createStrictMock(Response.class);
+
+ HttpHeaders httpHeaders = createNiceMock(HttpHeaders.class);
+ UriInfo uriInfo = createNiceMock(UriInfo.class);
+
+ String clusterName = "clusterName";
+ String hostName = "hostName";
+
+ // expectations
+ expect(requestFactory.createRequest(eq(httpHeaders), isNull(String.class), eq(uriInfo), eq(Request.Type.DELETE),
+ eq(resourceDef))).andReturn(request);
+
+ expect(requestHandler.handleRequest(request)).andReturn(result);
+ expect(request.getResultSerializer()).andReturn(resultSerializer);
+ expect(resultSerializer.serialize(result, uriInfo)).andReturn(serializedResult);
+ expect(responseFactory.createResponse(serializedResult)).andReturn(response);
+
+ replay(resourceDef, resultSerializer, requestFactory, responseFactory, request, requestHandler,
+ result, response, httpHeaders, uriInfo);
+
+ //test
+ HostService hostService = new TestHostService(resourceDef, clusterName, hostName, requestFactory, responseFactory, requestHandler);
+ assertSame(response, hostService.deleteHost(httpHeaders, uriInfo, hostName));
+
+ verify(resourceDef, resultSerializer, requestFactory, responseFactory, request, requestHandler,
+ result, response, httpHeaders, uriInfo);
+ }
+
+
private class TestHostService extends HostService {
private RequestFactory m_requestFactory;
private ResponseFactory m_responseFactory;
Modified: incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/services/ServiceServiceTest.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/services/ServiceServiceTest.java?rev=1395830&r1=1395829&r2=1395830&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/services/ServiceServiceTest.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/services/ServiceServiceTest.java Tue Oct 9 00:55:06 2012
@@ -1,7 +1,7 @@
package org.apache.ambari.api.services;
import org.apache.ambari.api.handlers.RequestHandler;
-import org.apache.ambari.api.resource.ResourceDefinition;
+import org.apache.ambari.api.resources.ResourceDefinition;
import org.apache.ambari.api.services.serializers.ResultSerializer;
import org.junit.Test;
@@ -42,7 +42,7 @@ public class ServiceServiceTest {
String serviceName = "serviceName";
// expectations
- expect(requestFactory.createRequest(eq(httpHeaders), eq(uriInfo), eq(Request.Type.GET),
+ expect(requestFactory.createRequest(eq(httpHeaders), isNull(String.class), eq(uriInfo), eq(Request.Type.GET),
eq(resourceDef))).andReturn(request);
expect(requestHandler.handleRequest(request)).andReturn(result);
@@ -79,7 +79,7 @@ public class ServiceServiceTest {
String clusterName = "clusterName";
// expectations
- expect(requestFactory.createRequest(eq(httpHeaders), eq(uriInfo), eq(Request.Type.GET),
+ expect(requestFactory.createRequest(eq(httpHeaders), isNull(String.class), eq(uriInfo), eq(Request.Type.GET),
eq(resourceDef))).andReturn(request);
expect(requestHandler.handleRequest(request)).andReturn(result);
@@ -117,7 +117,7 @@ public class ServiceServiceTest {
String serviceName = "serviceName";
// expectations
- expect(requestFactory.createRequest(eq(httpHeaders), eq(uriInfo), eq(Request.Type.PUT),
+ expect(requestFactory.createRequest(eq(httpHeaders), eq("body"), eq(uriInfo), eq(Request.Type.PUT),
eq(resourceDef))).andReturn(request);
expect(requestHandler.handleRequest(request)).andReturn(result);
@@ -130,7 +130,7 @@ public class ServiceServiceTest {
//test
ServiceService hostService = new TestServiceService(resourceDef, clusterName, serviceName, requestFactory, responseFactory, requestHandler);
- assertSame(response, hostService.createService(httpHeaders, uriInfo, serviceName));
+ assertSame(response, hostService.createService("body", httpHeaders, uriInfo, serviceName));
verify(resourceDef, resultSerializer, requestFactory, responseFactory, request, requestHandler,
result, response, httpHeaders, uriInfo);
@@ -155,7 +155,7 @@ public class ServiceServiceTest {
String serviceName = "serviceName";
// expectations
- expect(requestFactory.createRequest(eq(httpHeaders), eq(uriInfo), eq(Request.Type.POST),
+ expect(requestFactory.createRequest(eq(httpHeaders), eq("body"), eq(uriInfo), eq(Request.Type.POST),
eq(resourceDef))).andReturn(request);
expect(requestHandler.handleRequest(request)).andReturn(result);
@@ -168,7 +168,7 @@ public class ServiceServiceTest {
//test
ServiceService hostService = new TestServiceService(resourceDef, clusterName, serviceName, requestFactory, responseFactory, requestHandler);
- assertSame(response, hostService.updateService(httpHeaders, uriInfo, serviceName));
+ assertSame(response, hostService.updateService("body", httpHeaders, uriInfo, serviceName));
verify(resourceDef, resultSerializer, requestFactory, responseFactory, request, requestHandler,
result, response, httpHeaders, uriInfo);
@@ -193,7 +193,7 @@ public class ServiceServiceTest {
String serviceName = "serviceName";
// expectations
- expect(requestFactory.createRequest(eq(httpHeaders), eq(uriInfo), eq(Request.Type.DELETE),
+ expect(requestFactory.createRequest(eq(httpHeaders), isNull(String.class), eq(uriInfo), eq(Request.Type.DELETE),
eq(resourceDef))).andReturn(request);
expect(requestHandler.handleRequest(request)).andReturn(result);
Added: incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/services/UpdatePersistenceManagerTest.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/services/UpdatePersistenceManagerTest.java?rev=1395830&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/services/UpdatePersistenceManagerTest.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/services/UpdatePersistenceManagerTest.java Tue Oct 9 00:55:06 2012
@@ -0,0 +1,94 @@
+/**
+ * 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.ambari.api.services;
+
+
+import org.apache.ambari.api.controller.utilities.Properties;
+import org.apache.ambari.api.query.Query;
+import org.apache.ambari.api.resources.ResourceDefinition;
+import org.apache.ambari.server.controller.spi.*;
+import org.junit.Test;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.junit.Assert.*;
+
+import static org.easymock.EasyMock.*;
+
+/**
+ * Unit tests for UpdatePersistenceManager.
+ */
+public class UpdatePersistenceManagerTest {
+ @Test
+ public void testPersist() throws Exception {
+ ResourceDefinition resource = createMock(ResourceDefinition.class);
+ ClusterController controller = createMock(ClusterController.class);
+ Schema schema = createMock(Schema.class);
+ org.apache.ambari.server.controller.spi.Request serverRequest =
+ createStrictMock(org.apache.ambari.server.controller.spi.Request.class);
+ Query query = createMock(Query.class);
+ Predicate predicate = createMock(Predicate.class);
+
+
+ Map<PropertyId, Object> mapProperties = new HashMap<PropertyId, Object>();
+ mapProperties.put(Properties.getPropertyId("bar", "foo"), "value");
+
+ //expectations
+ expect(resource.getType()).andReturn(Resource.Type.Component);
+ expect(resource.getProperties()).andReturn(mapProperties);
+ expect(resource.getQuery()).andReturn(query);
+ expect(query.getPredicate()).andReturn(predicate);
+
+ controller.updateResources(Resource.Type.Component, serverRequest, predicate);
+
+ replay(resource, controller, schema, serverRequest, query, predicate);
+
+ new TestUpdatePersistenceManager(controller, mapProperties, serverRequest).persist(resource);
+
+ verify(resource, controller, schema, serverRequest, query, predicate);
+ }
+
+ private class TestUpdatePersistenceManager extends UpdatePersistenceManager {
+
+ private ClusterController m_controller;
+ private org.apache.ambari.server.controller.spi.Request m_request;
+ private Map<PropertyId, Object> m_mapProperties;
+
+ private TestUpdatePersistenceManager(ClusterController controller,
+ Map<PropertyId, Object> mapProperties,
+ org.apache.ambari.server.controller.spi.Request controllerRequest) {
+ m_controller = controller;
+ m_mapProperties = mapProperties;
+ m_request = controllerRequest;
+ }
+
+ @Override
+ protected ClusterController getClusterController() {
+ return m_controller;
+ }
+
+ @Override
+ protected org.apache.ambari.server.controller.spi.Request createControllerRequest(Map<PropertyId, Object> properties) {
+ assertEquals(m_mapProperties, properties);
+ return m_request;
+ }
+ }
+
+}
Added: incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/services/parsers/JsonPropertyParserTest.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/services/parsers/JsonPropertyParserTest.java?rev=1395830&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/services/parsers/JsonPropertyParserTest.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/services/parsers/JsonPropertyParserTest.java Tue Oct 9 00:55:06 2012
@@ -0,0 +1,66 @@
+/**
+ * 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.ambari.api.services.parsers;
+
+import org.apache.ambari.api.controller.utilities.Properties;
+import org.apache.ambari.server.controller.spi.PropertyId;
+import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Unit tests for JsonPropertyParser.
+ */
+public class JsonPropertyParserTest {
+
+ String serviceJson = "{\"Services\" : {" +
+ " \"display_name\" : \"HDFS\"," +
+ " \"description\" : \"Apache Hadoop Distributed File System\"," +
+ " \"attributes\" : \"{ \\\"runnable\\\": true, \\\"mustInstall\\\": true, \\\"editable\\\": false, \\\"noDisplay\\\": false }\"," +
+ " \"service_name\" : \"HDFS\"" +
+ " }," +
+ " \"ServiceInfo\" : {" +
+ " \"cluster_name\" : \"tbmetrictest\"," +
+ " \"state\" : \"STARTED\"" +
+ " }," +
+ "\"OuterCategory\" : { \"propName\" : 100, \"nested1\" : { \"nested2\" : { \"innerPropName\" : \"innerPropValue\" } } } }";
+
+
+ @Test
+ public void testParse() throws Exception {
+ RequestBodyParser parser = new JsonPropertyParser();
+ Map<PropertyId, Object> mapProps = parser.parse(serviceJson);
+
+ Map<PropertyId, Object> mapExpected = new HashMap<PropertyId, Object>();
+ mapExpected.put(Properties.getPropertyId("service_name", "Services"), "HDFS");
+ mapExpected.put(Properties.getPropertyId("display_name", "Services"), "HDFS");
+ mapExpected.put(Properties.getPropertyId("cluster_name", "ServiceInfo"), "tbmetrictest");
+ mapExpected.put(Properties.getPropertyId("attributes", "Services"), "{ \"runnable\": true, \"mustInstall\": true, \"editable\": false, \"noDisplay\": false }");
+ mapExpected.put(Properties.getPropertyId("description", "Services"), "Apache Hadoop Distributed File System");
+ mapExpected.put(Properties.getPropertyId("state", "ServiceInfo"), "STARTED");
+ mapExpected.put(Properties.getPropertyId("propName", "OuterCategory"), "100");
+ mapExpected.put(Properties.getPropertyId("innerPropName", "OuterCategory.nested1.nested2"), "innerPropValue");
+
+ assertEquals(mapExpected, mapProps);
+ }
+}
+
+
Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/controller/predicate/ResourceImpl.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/controller/predicate/ResourceImpl.java?rev=1395830&r1=1395829&r2=1395830&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/controller/predicate/ResourceImpl.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/controller/predicate/ResourceImpl.java Tue Oct 9 00:55:06 2012
@@ -25,17 +25,17 @@ import java.util.HashMap;
import java.util.Map;
/**
- * Simple resource implementation.
+ * Simple resources implementation.
*/
public class ResourceImpl implements Resource {
/**
- * The resource type.
+ * The resources type.
*/
private final Type type;
/**
- * The map of categories/properties for this resource.
+ * The map of categories/properties for this resources.
*/
private final Map<String, Map<String, String>> categories = new HashMap<String, Map<String, String>>();
@@ -43,9 +43,9 @@ public class ResourceImpl implements Res
// ----- Constructors ------------------------------------------------------
/**
- * Create a resource of the given type.
+ * Create a resources of the given type.
*
- * @param type the resource type
+ * @param type the resources type
*/
public ResourceImpl(Type type) {
this.type = type;
Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/resources/TestResources.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/resources/TestResources.java?rev=1395830&r1=1395829&r2=1395830&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/resources/TestResources.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/resources/TestResources.java Tue Oct 9 00:55:06 2012
@@ -40,7 +40,7 @@ import com.google.inject.Injector;
public class TestResources extends TestCase {
private static ResourceManager resMan;
- private static final String RESOURCE_FILE_NAME = "resource.ext";
+ private static final String RESOURCE_FILE_NAME = "resources.ext";
private static final String RESOURCE_FILE_CONTENT = "CONTENT";
Injector injector;
private TemporaryFolder tempFolder = new TemporaryFolder();