You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by bi...@apache.org on 2013/04/05 16:34:31 UTC

svn commit: r1464989 [2/2] - in /incubator/ambari/trunk: ./ ambari-server/src/main/java/org/apache/ambari/server/api/resources/ ambari-server/src/main/java/org/apache/ambari/server/api/services/ ambari-server/src/main/java/org/apache/ambari/server/cont...

Added: incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/api/resources/JobResourceDefinitionTest.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/api/resources/JobResourceDefinitionTest.java?rev=1464989&view=auto
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/api/resources/JobResourceDefinitionTest.java (added)
+++ incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/api/resources/JobResourceDefinitionTest.java Fri Apr  5 14:34:30 2013
@@ -0,0 +1,52 @@
+/*
+ * 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.server.api.resources;
+
+import java.util.Set;
+
+import org.apache.ambari.server.controller.spi.Resource;
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * Tests for JobResourceDefinition.
+ */
+public class JobResourceDefinitionTest {
+  @Test
+  public void testGetPluralName() throws Exception {
+    JobResourceDefinition definition = new JobResourceDefinition();
+    Assert.assertEquals("jobs", definition.getPluralName());
+  }
+
+  @Test
+  public void testGetSingularName() throws Exception {
+    JobResourceDefinition definition = new JobResourceDefinition();
+    Assert.assertEquals("job", definition.getSingularName());
+  }
+
+  @Test
+  public void testGetSubResourceDefinitions() throws Exception {
+    JobResourceDefinition definition = new JobResourceDefinition();
+    Set<SubResourceDefinition> subResourceDefinitions = definition
+        .getSubResourceDefinitions();
+    Assert.assertEquals(1, subResourceDefinitions.size());
+    SubResourceDefinition subResourceDefinition = subResourceDefinitions
+        .iterator().next();
+    Assert.assertEquals(Resource.Type.TaskAttempt,
+        subResourceDefinition.getType());
+  }
+}

Propchange: incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/api/resources/JobResourceDefinitionTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/api/resources/TaskAttemptResourceDefinitionTest.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/api/resources/TaskAttemptResourceDefinitionTest.java?rev=1464989&view=auto
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/api/resources/TaskAttemptResourceDefinitionTest.java (added)
+++ incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/api/resources/TaskAttemptResourceDefinitionTest.java Fri Apr  5 14:34:30 2013
@@ -0,0 +1,47 @@
+/*
+ * 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.server.api.resources;
+
+import java.util.Set;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * Tests for TaskAttemptResourceDefinition.
+ */
+public class TaskAttemptResourceDefinitionTest {
+  @Test
+  public void testGetPluralName() throws Exception {
+    TaskAttemptResourceDefinition definition = new TaskAttemptResourceDefinition();
+    Assert.assertEquals("taskattempts", definition.getPluralName());
+  }
+
+  @Test
+  public void testGetSingularName() throws Exception {
+    TaskAttemptResourceDefinition definition = new TaskAttemptResourceDefinition();
+    Assert.assertEquals("taskattempt", definition.getSingularName());
+  }
+
+  @Test
+  public void testGetSubResourceDefinitions() throws Exception {
+    TaskAttemptResourceDefinition definition = new TaskAttemptResourceDefinition();
+    Set<SubResourceDefinition> subResourceDefinitions = definition
+        .getSubResourceDefinitions();
+    Assert.assertEquals(0, subResourceDefinitions.size());
+  }
+}

Propchange: incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/api/resources/TaskAttemptResourceDefinitionTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/api/resources/WorkflowResourceDefinitionTest.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/api/resources/WorkflowResourceDefinitionTest.java?rev=1464989&view=auto
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/api/resources/WorkflowResourceDefinitionTest.java (added)
+++ incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/api/resources/WorkflowResourceDefinitionTest.java Fri Apr  5 14:34:30 2013
@@ -0,0 +1,51 @@
+/*
+ * 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.server.api.resources;
+
+import java.util.Set;
+
+import org.apache.ambari.server.controller.spi.Resource;
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * Tests for WorkflowResourceDefinition.
+ */
+public class WorkflowResourceDefinitionTest {
+  @Test
+  public void testGetPluralName() throws Exception {
+    WorkflowResourceDefinition definition = new WorkflowResourceDefinition();
+    Assert.assertEquals("workflows", definition.getPluralName());
+  }
+
+  @Test
+  public void testGetSingularName() throws Exception {
+    WorkflowResourceDefinition definition = new WorkflowResourceDefinition();
+    Assert.assertEquals("workflow", definition.getSingularName());
+  }
+
+  @Test
+  public void testGetSubResourceDefinitions() throws Exception {
+    WorkflowResourceDefinition definition = new WorkflowResourceDefinition();
+    Set<SubResourceDefinition> subResourceDefinitions = definition
+        .getSubResourceDefinitions();
+    Assert.assertEquals(1, subResourceDefinitions.size());
+    SubResourceDefinition subResourceDefinition = subResourceDefinitions
+        .iterator().next();
+    Assert.assertEquals(Resource.Type.Job, subResourceDefinition.getType());
+  }
+}

Propchange: incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/api/resources/WorkflowResourceDefinitionTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/api/services/JobServiceTest.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/api/services/JobServiceTest.java?rev=1464989&view=auto
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/api/services/JobServiceTest.java (added)
+++ incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/api/services/JobServiceTest.java Fri Apr  5 14:34:30 2013
@@ -0,0 +1,93 @@
+/*
+ * 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.server.api.services;
+
+import static org.junit.Assert.assertEquals;
+
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.UriInfo;
+
+import org.apache.ambari.server.api.resources.ResourceInstance;
+import org.apache.ambari.server.api.services.parsers.RequestBodyParser;
+import org.apache.ambari.server.api.services.serializers.ResultSerializer;
+
+/**
+ * Unit tests for JobService.
+ */
+public class JobServiceTest extends BaseServiceTest {
+
+  @Override
+  public List<ServiceTestInvocation> getTestInvocations() throws Exception {
+    List<ServiceTestInvocation> listInvocations = new ArrayList<ServiceTestInvocation>();
+
+    // getJob
+    JobService service = new TestJobService("clusterName", "jobId");
+    Method m = service.getClass().getMethod("getJob", HttpHeaders.class,
+        UriInfo.class, String.class);
+    Object[] args = new Object[] {getHttpHeaders(), getUriInfo(), "jobId"};
+    listInvocations.add(new ServiceTestInvocation(Request.Type.GET, service, m,
+        args, null));
+
+    // getJobs
+    service = new TestJobService("clusterName", null);
+    m = service.getClass().getMethod("getJobs", HttpHeaders.class,
+        UriInfo.class);
+    args = new Object[] {getHttpHeaders(), getUriInfo()};
+    listInvocations.add(new ServiceTestInvocation(Request.Type.GET, service, m,
+        args, null));
+
+    return listInvocations;
+  }
+
+  private class TestJobService extends JobService {
+    private String workflowId;
+    private String clusterName;
+
+    public TestJobService(String clusterName, String workflowId) {
+      super(clusterName, workflowId);
+      this.clusterName = clusterName;
+      this.workflowId = workflowId;
+    }
+
+    @Override
+    ResourceInstance createJobResource(String clusterName, String workflowId,
+        String jobId) {
+      assertEquals(this.clusterName, clusterName);
+      assertEquals(this.workflowId, workflowId);
+      return getTestResource();
+    }
+
+    @Override
+    RequestFactory getRequestFactory() {
+      return getTestRequestFactory();
+    }
+
+    @Override
+    protected RequestBodyParser getBodyParser() {
+      return getTestBodyParser();
+    }
+
+    @Override
+    protected ResultSerializer getResultSerializer() {
+      return getTestResultSerializer();
+    }
+  }
+}

Propchange: incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/api/services/JobServiceTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/api/services/TaskAttemptServiceTest.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/api/services/TaskAttemptServiceTest.java?rev=1464989&view=auto
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/api/services/TaskAttemptServiceTest.java (added)
+++ incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/api/services/TaskAttemptServiceTest.java Fri Apr  5 14:34:30 2013
@@ -0,0 +1,98 @@
+/*
+ * 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.server.api.services;
+
+import static org.junit.Assert.assertEquals;
+
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.UriInfo;
+
+import org.apache.ambari.server.api.resources.ResourceInstance;
+import org.apache.ambari.server.api.services.parsers.RequestBodyParser;
+import org.apache.ambari.server.api.services.serializers.ResultSerializer;
+
+/**
+ * Unit tests for TaskAttemptService.
+ */
+public class TaskAttemptServiceTest extends BaseServiceTest {
+
+  @Override
+  public List<ServiceTestInvocation> getTestInvocations() throws Exception {
+    List<ServiceTestInvocation> listInvocations = new ArrayList<ServiceTestInvocation>();
+
+    // getTaskAttempt
+    TestTaskAttemptService service = new TestTaskAttemptService("clusterName",
+        "workflowId", "jobId");
+    Method m = service.getClass().getMethod("getTaskAttempt",
+        HttpHeaders.class, UriInfo.class, String.class);
+    Object[] args = new Object[] {getHttpHeaders(), getUriInfo(), "jobId"};
+    listInvocations.add(new ServiceTestInvocation(Request.Type.GET, service, m,
+        args, null));
+
+    // getTaskAttempts
+    service = new TestTaskAttemptService("clusterName", "workflowId", "jobId");
+    m = service.getClass().getMethod("getTaskAttempts", HttpHeaders.class,
+        UriInfo.class);
+    args = new Object[] {getHttpHeaders(), getUriInfo()};
+    listInvocations.add(new ServiceTestInvocation(Request.Type.GET, service, m,
+        args, null));
+
+    return listInvocations;
+  }
+
+  private class TestTaskAttemptService extends TaskAttemptService {
+    private String clusterName;
+    private String workflowId;
+    private String jobId;
+
+    public TestTaskAttemptService(String clusterName, String workflowId,
+        String jobId) {
+      super(clusterName, workflowId, jobId);
+      this.clusterName = clusterName;
+      this.workflowId = workflowId;
+      this.jobId = jobId;
+    }
+
+    @Override
+    ResourceInstance createTaskAttemptResource(String clusterName,
+        String workflowId, String jobId, String taskAttemptId) {
+      assertEquals(this.clusterName, clusterName);
+      assertEquals(this.workflowId, workflowId);
+      assertEquals(this.jobId, jobId);
+      return getTestResource();
+    }
+
+    @Override
+    RequestFactory getRequestFactory() {
+      return getTestRequestFactory();
+    }
+
+    @Override
+    protected RequestBodyParser getBodyParser() {
+      return getTestBodyParser();
+    }
+
+    @Override
+    protected ResultSerializer getResultSerializer() {
+      return getTestResultSerializer();
+    }
+  }
+}

Propchange: incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/api/services/TaskAttemptServiceTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/api/services/WorkflowServiceTest.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/api/services/WorkflowServiceTest.java?rev=1464989&view=auto
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/api/services/WorkflowServiceTest.java (added)
+++ incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/api/services/WorkflowServiceTest.java Fri Apr  5 14:34:30 2013
@@ -0,0 +1,90 @@
+/*
+ * 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.server.api.services;
+
+import static org.junit.Assert.assertEquals;
+
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.UriInfo;
+
+import org.apache.ambari.server.api.resources.ResourceInstance;
+import org.apache.ambari.server.api.services.parsers.RequestBodyParser;
+import org.apache.ambari.server.api.services.serializers.ResultSerializer;
+
+/**
+ * Unit tests for WorkflowService.
+ */
+public class WorkflowServiceTest extends BaseServiceTest {
+
+  @Override
+  public List<ServiceTestInvocation> getTestInvocations() throws Exception {
+    List<ServiceTestInvocation> listInvocations = new ArrayList<ServiceTestInvocation>();
+
+    // getWorkflow
+    WorkflowService service = new TestWorkflowService("clusterName");
+    Method m = service.getClass().getMethod("getWorkflow", HttpHeaders.class,
+        UriInfo.class, String.class);
+    Object[] args = new Object[] {getHttpHeaders(), getUriInfo(), "jobId"};
+    listInvocations.add(new ServiceTestInvocation(Request.Type.GET, service, m,
+        args, null));
+
+    // getWorkflows
+    service = new TestWorkflowService("clusterName");
+    m = service.getClass().getMethod("getWorkflows", HttpHeaders.class,
+        UriInfo.class);
+    args = new Object[] {getHttpHeaders(), getUriInfo()};
+    listInvocations.add(new ServiceTestInvocation(Request.Type.GET, service, m,
+        args, null));
+
+    return listInvocations;
+  }
+
+  private class TestWorkflowService extends WorkflowService {
+    private String clusterName;
+
+    public TestWorkflowService(String clusterName) {
+      super(clusterName);
+      this.clusterName = clusterName;
+    }
+
+    @Override
+    ResourceInstance createWorkflowResource(String clusterName,
+        String workflowId) {
+      assertEquals(this.clusterName, clusterName);
+      return getTestResource();
+    }
+
+    @Override
+    RequestFactory getRequestFactory() {
+      return getTestRequestFactory();
+    }
+
+    @Override
+    protected RequestBodyParser getBodyParser() {
+      return getTestBodyParser();
+    }
+
+    @Override
+    protected ResultSerializer getResultSerializer() {
+      return getTestResultSerializer();
+    }
+  }
+}

Propchange: incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/api/services/WorkflowServiceTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/AbstractJDBCResourceProviderTest.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/AbstractJDBCResourceProviderTest.java?rev=1464989&view=auto
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/AbstractJDBCResourceProviderTest.java (added)
+++ incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/AbstractJDBCResourceProviderTest.java Fri Apr  5 14:34:30 2013
@@ -0,0 +1,143 @@
+/*
+ * 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.server.controller.internal;
+
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.verify;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeSet;
+
+import org.apache.ambari.server.controller.spi.NoSuchParentResourceException;
+import org.apache.ambari.server.controller.spi.NoSuchResourceException;
+import org.apache.ambari.server.controller.spi.Predicate;
+import org.apache.ambari.server.controller.spi.Request;
+import org.apache.ambari.server.controller.spi.RequestStatus;
+import org.apache.ambari.server.controller.spi.Resource;
+import org.apache.ambari.server.controller.spi.Resource.Type;
+import org.apache.ambari.server.controller.spi.ResourceAlreadyExistsException;
+import org.apache.ambari.server.controller.spi.SystemException;
+import org.apache.ambari.server.controller.spi.UnsupportedPropertyException;
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * AbstractJDBCResourceProvider tests.
+ */
+public class AbstractJDBCResourceProviderTest {
+  private static final String property1 = "property1";
+  private static final String property2 = "property2";
+
+  @Test
+  public void test() throws SQLException {
+    Set<String> requestedIds = new TreeSet<String>();
+    requestedIds.add(property1);
+    requestedIds.add("none1");
+    requestedIds.add(property2);
+
+    AbstractJDBCResourceProvider<TestFields> provider = new TestAbstractJDBCResourceProviderImpl(
+        requestedIds, null);
+    Assert.assertEquals(
+        TestFields.field1.toString() + "," + TestFields.field2.toString(),
+        provider.getDBFieldString(requestedIds));
+    Assert.assertEquals(TestFields.field1.toString(),
+        provider.getDBFieldString(Collections.singleton(property1)));
+    Assert.assertEquals("",
+        provider.getDBFieldString(Collections.singleton("none1")));
+    Assert.assertEquals(TestFields.field1, provider.getDBField(property1));
+    Assert.assertEquals(TestFields.field2, provider.getDBField(property2));
+
+    ResultSet rs = createMock(ResultSet.class);
+    expect(rs.getString(TestFields.field1.toString())).andReturn("1").once();
+    expect(rs.getLong(TestFields.field2.toString())).andReturn(2l).once();
+    expect(rs.getInt(TestFields.field1.toString())).andReturn(3).once();
+    replay(rs);
+    Resource r = new ResourceImpl((Resource.Type) null);
+    provider.setString(r, property1, rs, requestedIds);
+    provider.setString(r, "none2", rs, requestedIds);
+    Assert.assertEquals("1", r.getPropertyValue(property1));
+    r = new ResourceImpl((Resource.Type) null);
+    provider.setLong(r, property2, rs, requestedIds);
+    provider.setLong(r, "none2", rs, requestedIds);
+    Assert.assertEquals(2l, r.getPropertyValue(property2));
+    r = new ResourceImpl((Resource.Type) null);
+    provider.setInt(r, property1, rs, requestedIds);
+    provider.setInt(r, "none2", rs, requestedIds);
+    Assert.assertEquals(3, r.getPropertyValue(property1));
+    verify(rs);
+  }
+
+  private static enum TestFields {
+    field1, field2
+  }
+
+  private static class TestAbstractJDBCResourceProviderImpl extends
+      AbstractJDBCResourceProvider<TestFields> {
+    protected TestAbstractJDBCResourceProviderImpl(Set<String> propertyIds,
+        Map<Type,String> keyPropertyIds) {
+      super(propertyIds, keyPropertyIds);
+    }
+
+    @Override
+    public RequestStatus createResources(Request request)
+        throws SystemException, UnsupportedPropertyException,
+        ResourceAlreadyExistsException, NoSuchParentResourceException {
+      return null;
+    }
+
+    @Override
+    public Set<Resource> getResources(Request request, Predicate predicate)
+        throws SystemException, UnsupportedPropertyException,
+        NoSuchResourceException, NoSuchParentResourceException {
+      return null;
+    }
+
+    @Override
+    public RequestStatus updateResources(Request request, Predicate predicate)
+        throws SystemException, UnsupportedPropertyException,
+        NoSuchResourceException, NoSuchParentResourceException {
+      return null;
+    }
+
+    @Override
+    public RequestStatus deleteResources(Predicate predicate)
+        throws SystemException, UnsupportedPropertyException,
+        NoSuchResourceException, NoSuchParentResourceException {
+      return null;
+    }
+
+    @Override
+    protected Map<String,TestFields> getDBFieldMap() {
+      Map<String,TestFields> fields = new HashMap<String,TestFields>();
+      fields.put(property1, TestFields.field1);
+      fields.put(property2, TestFields.field2);
+      return fields;
+    }
+
+    @Override
+    protected Set<String> getPKPropertyIds() {
+      return null;
+    }
+  }
+}

Propchange: incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/AbstractJDBCResourceProviderTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/JobResourceProviderTest.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/JobResourceProviderTest.java?rev=1464989&view=auto
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/JobResourceProviderTest.java (added)
+++ incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/JobResourceProviderTest.java Fri Apr  5 14:34:30 2013
@@ -0,0 +1,267 @@
+/*
+ * 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.server.controller.internal;
+
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.expectLastCall;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.verify;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.ambari.server.controller.internal.JobResourceProvider.JobFetcher;
+import org.apache.ambari.server.controller.jdbc.ConnectionFactory;
+import org.apache.ambari.server.controller.spi.NoSuchParentResourceException;
+import org.apache.ambari.server.controller.spi.NoSuchResourceException;
+import org.apache.ambari.server.controller.spi.Predicate;
+import org.apache.ambari.server.controller.spi.Request;
+import org.apache.ambari.server.controller.spi.Resource;
+import org.apache.ambari.server.controller.spi.Resource.Type;
+import org.apache.ambari.server.controller.spi.ResourceProvider;
+import org.apache.ambari.server.controller.spi.SystemException;
+import org.apache.ambari.server.controller.spi.UnsupportedPropertyException;
+import org.apache.ambari.server.controller.utilities.PredicateBuilder;
+import org.apache.ambari.server.controller.utilities.PropertyHelper;
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * JobResourceProvider tests.
+ */
+public class JobResourceProviderTest {
+  @Test
+  public void testGetResources() throws SystemException,
+      UnsupportedPropertyException, NoSuchResourceException,
+      NoSuchParentResourceException {
+    Set<Resource> expected = new HashSet<Resource>();
+    expected.add(createJobResponse("Cluster100", "workflow1", "job1"));
+    expected.add(createJobResponse("Cluster100", "workflow2", "job2"));
+    expected.add(createJobResponse("Cluster100", "workflow2", "job3"));
+
+    Resource.Type type = Resource.Type.Job;
+    Set<String> propertyIds = PropertyHelper.getPropertyIds(type);
+
+    JobFetcher jobFetcher = createMock(JobFetcher.class);
+    expect(jobFetcher.fetchJobDetails(propertyIds, null, "workflow2", null))
+        .andReturn(expected).once();
+    replay(jobFetcher);
+
+    Map<Resource.Type,String> keyPropertyIds = PropertyHelper
+        .getKeyPropertyIds(type);
+    ResourceProvider provider = new JobResourceProvider(propertyIds,
+        keyPropertyIds, jobFetcher);
+
+    Request request = PropertyHelper.getReadRequest(propertyIds);
+    Predicate predicate = new PredicateBuilder()
+        .property(JobResourceProvider.JOB_WORKFLOW_ID_PROPERTY_ID)
+        .equals("workflow2").toPredicate();
+    Set<Resource> resources = provider.getResources(request, predicate);
+
+    Assert.assertEquals(3, resources.size());
+    Set<String> names = new HashSet<String>();
+    for (Resource resource : resources) {
+      String clusterName = (String) resource
+          .getPropertyValue(JobResourceProvider.JOB_CLUSTER_NAME_PROPERTY_ID);
+      Assert.assertEquals("Cluster100", clusterName);
+      names.add((String) resource
+          .getPropertyValue(JobResourceProvider.JOB_ID_PROPERTY_ID));
+    }
+    // Make sure that all of the response objects got moved into resources
+    for (Resource resource : expected) {
+      Assert.assertTrue(names.contains(resource
+          .getPropertyValue(JobResourceProvider.JOB_ID_PROPERTY_ID)));
+    }
+
+    verify(jobFetcher);
+  }
+
+  @Test
+  public void testJobFetcher1() throws SystemException,
+      UnsupportedPropertyException, NoSuchResourceException,
+      NoSuchParentResourceException {
+    Set<String> requestedIds = new HashSet<String>();
+    requestedIds.add(JobResourceProvider.JOB_ID_PROPERTY_ID);
+
+    Map<Resource.Type,String> keyPropertyIds = PropertyHelper
+        .getKeyPropertyIds(Resource.Type.Job);
+    ResourceProvider provider = new TestJobResourceProvider(requestedIds,
+        keyPropertyIds, 1);
+
+    Request request = PropertyHelper.getReadRequest(requestedIds);
+    Predicate predicate = new PredicateBuilder()
+        .property(JobResourceProvider.JOB_ID_PROPERTY_ID).equals("job1")
+        .toPredicate();
+    Set<Resource> resources = provider.getResources(request, predicate);
+
+    Assert.assertEquals(1, resources.size());
+    for (Resource resource : resources) {
+      String workflowId = (String) resource
+          .getPropertyValue(JobResourceProvider.JOB_ID_PROPERTY_ID);
+      Assert.assertEquals("job1", workflowId);
+    }
+  }
+
+  @Test
+  public void testJobFetcher2() throws SystemException,
+      UnsupportedPropertyException, NoSuchResourceException,
+      NoSuchParentResourceException {
+    Set<String> requestedIds = new HashSet<String>();
+    requestedIds.add(JobResourceProvider.JOB_ID_PROPERTY_ID);
+    requestedIds.add(JobResourceProvider.JOB_SUBMIT_TIME_PROPERTY_ID);
+
+    Map<Resource.Type,String> keyPropertyIds = PropertyHelper
+        .getKeyPropertyIds(Resource.Type.Job);
+    ResourceProvider provider = new TestJobResourceProvider(requestedIds,
+        keyPropertyIds, 2);
+
+    Request request = PropertyHelper.getReadRequest(requestedIds);
+    Predicate predicate = new PredicateBuilder()
+        .property(JobResourceProvider.JOB_ID_PROPERTY_ID).equals("job1")
+        .toPredicate();
+    Set<Resource> resources = provider.getResources(request, predicate);
+
+    Assert.assertEquals(1, resources.size());
+    for (Resource resource : resources) {
+      String workflowId = (String) resource
+          .getPropertyValue(JobResourceProvider.JOB_ID_PROPERTY_ID);
+      Assert.assertEquals("job1", workflowId);
+      Assert.assertEquals(42l, resource
+          .getPropertyValue(JobResourceProvider.JOB_SUBMIT_TIME_PROPERTY_ID));
+    }
+  }
+
+  @Test
+  public void testJobFetcher3() throws SystemException,
+      UnsupportedPropertyException, NoSuchResourceException,
+      NoSuchParentResourceException {
+    Set<String> requestedIds = new HashSet<String>();
+    requestedIds.add(JobResourceProvider.JOB_ID_PROPERTY_ID);
+    requestedIds.add(JobResourceProvider.JOB_ELAPSED_TIME_PROPERTY_ID);
+
+    Map<Resource.Type,String> keyPropertyIds = PropertyHelper
+        .getKeyPropertyIds(Resource.Type.Job);
+    ResourceProvider provider = new TestJobResourceProvider(requestedIds,
+        keyPropertyIds, 3);
+
+    Request request = PropertyHelper.getReadRequest(requestedIds);
+    Predicate predicate = new PredicateBuilder()
+        .property(JobResourceProvider.JOB_ID_PROPERTY_ID).equals("job1")
+        .toPredicate();
+    Set<Resource> resources = provider.getResources(request, predicate);
+
+    Assert.assertEquals(1, resources.size());
+    for (Resource resource : resources) {
+      String workflowId = (String) resource
+          .getPropertyValue(JobResourceProvider.JOB_ID_PROPERTY_ID);
+      Assert.assertEquals("job1", workflowId);
+      Assert.assertEquals(1l, resource
+          .getPropertyValue(JobResourceProvider.JOB_ELAPSED_TIME_PROPERTY_ID));
+    }
+  }
+
+  @Test
+  public void testJobFetcher4() throws SystemException,
+      UnsupportedPropertyException, NoSuchResourceException,
+      NoSuchParentResourceException {
+    Set<String> requestedIds = new HashSet<String>();
+    requestedIds.add(JobResourceProvider.JOB_ID_PROPERTY_ID);
+    requestedIds.add(JobResourceProvider.JOB_SUBMIT_TIME_PROPERTY_ID);
+    requestedIds.add(JobResourceProvider.JOB_ELAPSED_TIME_PROPERTY_ID);
+
+    Map<Resource.Type,String> keyPropertyIds = PropertyHelper
+        .getKeyPropertyIds(Resource.Type.Job);
+    ResourceProvider provider = new TestJobResourceProvider(requestedIds,
+        keyPropertyIds, 4);
+
+    Request request = PropertyHelper.getReadRequest(requestedIds);
+    Predicate predicate = new PredicateBuilder()
+        .property(JobResourceProvider.JOB_ID_PROPERTY_ID).equals("job1")
+        .toPredicate();
+    Set<Resource> resources = provider.getResources(request, predicate);
+
+    Assert.assertEquals(1, resources.size());
+    for (Resource resource : resources) {
+      String workflowId = (String) resource
+          .getPropertyValue(JobResourceProvider.JOB_ID_PROPERTY_ID);
+      Assert.assertEquals("job1", workflowId);
+      Assert.assertEquals(42l, resource
+          .getPropertyValue(JobResourceProvider.JOB_SUBMIT_TIME_PROPERTY_ID));
+      Assert.assertEquals(0l, resource
+          .getPropertyValue(JobResourceProvider.JOB_ELAPSED_TIME_PROPERTY_ID));
+    }
+  }
+
+  private static Resource createJobResponse(String clusterName,
+      String workflowId, String jobId) {
+    Resource r = new ResourceImpl(Resource.Type.Job);
+    r.setProperty(JobResourceProvider.JOB_CLUSTER_NAME_PROPERTY_ID, clusterName);
+    r.setProperty(JobResourceProvider.JOB_WORKFLOW_ID_PROPERTY_ID, workflowId);
+    r.setProperty(JobResourceProvider.JOB_ID_PROPERTY_ID, jobId);
+    return r;
+  }
+
+  private static class TestJobResourceProvider extends JobResourceProvider {
+    protected TestJobResourceProvider(Set<String> propertyIds,
+        Map<Type,String> keyPropertyIds, int type) {
+      super(propertyIds, keyPropertyIds);
+      this.jobFetcher = new TestJobFetcher(type);
+    }
+
+    private class TestJobFetcher extends PostgresJobFetcher {
+      ResultSet rs = null;
+      int type;
+
+      public TestJobFetcher(int type) {
+        super((ConnectionFactory) null);
+        this.type = type;
+      }
+
+      @Override
+      protected ResultSet getResultSet(Set<String> requestedIds,
+          String workflowId, String jobId) throws SQLException {
+        rs = createMock(ResultSet.class);
+        expect(rs.next()).andReturn(true).once();
+        expect(rs.getString(getDBField(JOB_ID_PROPERTY_ID).toString()))
+            .andReturn("job1").once();
+        if (type > 1)
+          expect(rs.getLong(getDBField(JOB_SUBMIT_TIME_PROPERTY_ID).toString()))
+              .andReturn(42l).once();
+        if (type == 3)
+          expect(rs.getLong(JobFields.FINISHTIME.toString())).andReturn(43l)
+              .once();
+        if (type == 4)
+          expect(rs.getLong(JobFields.FINISHTIME.toString())).andReturn(41l)
+              .once();
+        expect(rs.next()).andReturn(false).once();
+        rs.close();
+        expectLastCall().once();
+        replay(rs);
+        return rs;
+      }
+
+      @Override
+      protected void close() {
+        verify(rs);
+      }
+    }
+  }
+}

Propchange: incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/JobResourceProviderTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/TaskAttemptResourceProviderTest.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/TaskAttemptResourceProviderTest.java?rev=1464989&view=auto
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/TaskAttemptResourceProviderTest.java (added)
+++ incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/TaskAttemptResourceProviderTest.java Fri Apr  5 14:34:30 2013
@@ -0,0 +1,181 @@
+/*
+ * 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.server.controller.internal;
+
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.expectLastCall;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.verify;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.ambari.server.controller.internal.TaskAttemptResourceProvider.TaskAttemptFetcher;
+import org.apache.ambari.server.controller.jdbc.ConnectionFactory;
+import org.apache.ambari.server.controller.spi.NoSuchParentResourceException;
+import org.apache.ambari.server.controller.spi.NoSuchResourceException;
+import org.apache.ambari.server.controller.spi.Predicate;
+import org.apache.ambari.server.controller.spi.Request;
+import org.apache.ambari.server.controller.spi.Resource;
+import org.apache.ambari.server.controller.spi.Resource.Type;
+import org.apache.ambari.server.controller.spi.ResourceProvider;
+import org.apache.ambari.server.controller.spi.SystemException;
+import org.apache.ambari.server.controller.spi.UnsupportedPropertyException;
+import org.apache.ambari.server.controller.utilities.PredicateBuilder;
+import org.apache.ambari.server.controller.utilities.PropertyHelper;
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * TaskAttemptResourceProvider tests
+ */
+public class TaskAttemptResourceProviderTest {
+  @Test
+  public void testGetResources() throws SystemException,
+      UnsupportedPropertyException, NoSuchResourceException,
+      NoSuchParentResourceException {
+    Set<Resource> expected = new HashSet<Resource>();
+    expected.add(createTaskAttemptResponse("Cluster100", "workflow1", "job1",
+        "taskAttempt1"));
+    expected.add(createTaskAttemptResponse("Cluster100", "workflow2", "job2",
+        "taskAttempt2"));
+    expected.add(createTaskAttemptResponse("Cluster100", "workflow2", "job2",
+        "taskAttempt3"));
+
+    Resource.Type type = Resource.Type.TaskAttempt;
+    Set<String> propertyIds = PropertyHelper.getPropertyIds(type);
+
+    TaskAttemptFetcher taskAttemptFetcher = createMock(TaskAttemptFetcher.class);
+    expect(
+        taskAttemptFetcher.fetchTaskAttemptDetails(propertyIds, null, null,
+            "job2", null)).andReturn(expected).once();
+    replay(taskAttemptFetcher);
+
+    Map<Resource.Type,String> keyPropertyIds = PropertyHelper
+        .getKeyPropertyIds(type);
+    ResourceProvider provider = new TaskAttemptResourceProvider(propertyIds,
+        keyPropertyIds, taskAttemptFetcher);
+
+    Request request = PropertyHelper.getReadRequest(propertyIds);
+    Predicate predicate = new PredicateBuilder()
+        .property(TaskAttemptResourceProvider.TASK_ATTEMPT_JOB_ID_PROPERTY_ID)
+        .equals("job2").toPredicate();
+    Set<Resource> resources = provider.getResources(request, predicate);
+
+    Assert.assertEquals(3, resources.size());
+    Set<String> names = new HashSet<String>();
+    for (Resource resource : resources) {
+      String clusterName = (String) resource
+          .getPropertyValue(TaskAttemptResourceProvider.TASK_ATTEMPT_CLUSTER_NAME_PROPERTY_ID);
+      Assert.assertEquals("Cluster100", clusterName);
+      names
+          .add((String) resource
+              .getPropertyValue(TaskAttemptResourceProvider.TASK_ATTEMPT_ID_PROPERTY_ID));
+    }
+    // Make sure that all of the response objects got moved into resources
+    for (Resource resource : expected) {
+      Assert
+          .assertTrue(names.contains(resource
+              .getPropertyValue(TaskAttemptResourceProvider.TASK_ATTEMPT_ID_PROPERTY_ID)));
+    }
+
+    verify(taskAttemptFetcher);
+  }
+
+  @Test
+  public void testTaskAttemptFetcher() throws SystemException,
+      UnsupportedPropertyException, NoSuchResourceException,
+      NoSuchParentResourceException {
+    Set<String> requestedIds = new HashSet<String>();
+    requestedIds.add(TaskAttemptResourceProvider.TASK_ATTEMPT_ID_PROPERTY_ID);
+
+    Map<Resource.Type,String> keyPropertyIds = PropertyHelper
+        .getKeyPropertyIds(Resource.Type.TaskAttempt);
+    ResourceProvider provider = new TestTaskAttemptResourceProvider(
+        requestedIds, keyPropertyIds);
+
+    Request request = PropertyHelper.getReadRequest(requestedIds);
+    Predicate predicate = new PredicateBuilder()
+        .property(TaskAttemptResourceProvider.TASK_ATTEMPT_ID_PROPERTY_ID)
+        .equals("taskattempt1").toPredicate();
+    Set<Resource> resources = provider.getResources(request, predicate);
+
+    Assert.assertEquals(1, resources.size());
+    for (Resource resource : resources) {
+      String workflowId = (String) resource
+          .getPropertyValue(TaskAttemptResourceProvider.TASK_ATTEMPT_ID_PROPERTY_ID);
+      Assert.assertEquals("taskattempt1", workflowId);
+    }
+  }
+
+  private static Resource createTaskAttemptResponse(String clusterName,
+      String workflowId, String jobId, String taskAttemptId) {
+    Resource r = new ResourceImpl(Resource.Type.TaskAttempt);
+    r.setProperty(
+        TaskAttemptResourceProvider.TASK_ATTEMPT_CLUSTER_NAME_PROPERTY_ID,
+        clusterName);
+    r.setProperty(
+        TaskAttemptResourceProvider.TASK_ATTEMPT_WORKFLOW_ID_PROPERTY_ID,
+        workflowId);
+    r.setProperty(TaskAttemptResourceProvider.TASK_ATTEMPT_JOB_ID_PROPERTY_ID,
+        jobId);
+    r.setProperty(TaskAttemptResourceProvider.TASK_ATTEMPT_ID_PROPERTY_ID,
+        taskAttemptId);
+    return r;
+  }
+
+  private static class TestTaskAttemptResourceProvider extends
+      TaskAttemptResourceProvider {
+    protected TestTaskAttemptResourceProvider(Set<String> propertyIds,
+        Map<Type,String> keyPropertyIds) {
+      super(propertyIds, keyPropertyIds, null);
+      this.taskAttemptFetcher = new TestTaskAttemptFetcher();
+    }
+
+    private class TestTaskAttemptFetcher extends PostgresTaskAttemptFetcher {
+      ResultSet rs = null;
+
+      public TestTaskAttemptFetcher() {
+        super((ConnectionFactory) null);
+      }
+
+      @Override
+      protected ResultSet getResultSet(Set<String> requestedIds,
+          String workflowId, String jobId, String taskAttemptId)
+          throws SQLException {
+        rs = createMock(ResultSet.class);
+        expect(rs.next()).andReturn(true).once();
+        expect(rs.getString(getDBField(TASK_ATTEMPT_ID_PROPERTY_ID).toString()))
+            .andReturn("taskattempt1").once();
+        expect(rs.next()).andReturn(false).once();
+        rs.close();
+        expectLastCall().once();
+        replay(rs);
+        return rs;
+      }
+
+      @Override
+      protected void close() {
+        verify(rs);
+      }
+    }
+  }
+}

Propchange: incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/TaskAttemptResourceProviderTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/WorkflowResourceProviderTest.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/WorkflowResourceProviderTest.java?rev=1464989&view=auto
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/WorkflowResourceProviderTest.java (added)
+++ incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/WorkflowResourceProviderTest.java Fri Apr  5 14:34:30 2013
@@ -0,0 +1,167 @@
+/*
+ * 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.server.controller.internal;
+
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.expectLastCall;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.verify;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.ambari.server.controller.internal.WorkflowResourceProvider.WorkflowFetcher;
+import org.apache.ambari.server.controller.jdbc.ConnectionFactory;
+import org.apache.ambari.server.controller.spi.NoSuchParentResourceException;
+import org.apache.ambari.server.controller.spi.NoSuchResourceException;
+import org.apache.ambari.server.controller.spi.Predicate;
+import org.apache.ambari.server.controller.spi.Request;
+import org.apache.ambari.server.controller.spi.Resource;
+import org.apache.ambari.server.controller.spi.Resource.Type;
+import org.apache.ambari.server.controller.spi.ResourceProvider;
+import org.apache.ambari.server.controller.spi.SystemException;
+import org.apache.ambari.server.controller.spi.UnsupportedPropertyException;
+import org.apache.ambari.server.controller.utilities.PredicateBuilder;
+import org.apache.ambari.server.controller.utilities.PropertyHelper;
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * WorkflowResourceProvider tests.
+ */
+public class WorkflowResourceProviderTest {
+  @Test
+  public void testGetResources() throws SystemException,
+      UnsupportedPropertyException, NoSuchResourceException,
+      NoSuchParentResourceException {
+    Set<Resource> expected = new HashSet<Resource>();
+    expected.add(createWorkflowResponse("Cluster100", "workflow1"));
+    expected.add(createWorkflowResponse("Cluster100", "workflow2"));
+    expected.add(createWorkflowResponse("Cluster100", "workflow3"));
+
+    Resource.Type type = Resource.Type.Workflow;
+    Set<String> propertyIds = PropertyHelper.getPropertyIds(type);
+
+    WorkflowFetcher workflowFetcher = createMock(WorkflowFetcher.class);
+    expect(workflowFetcher.fetchWorkflows(propertyIds, "Cluster100", null))
+        .andReturn(expected).once();
+    replay(workflowFetcher);
+
+    Map<Resource.Type,String> keyPropertyIds = PropertyHelper
+        .getKeyPropertyIds(type);
+    ResourceProvider provider = new WorkflowResourceProvider(propertyIds,
+        keyPropertyIds, workflowFetcher);
+
+    Request request = PropertyHelper.getReadRequest(propertyIds);
+    Predicate predicate = new PredicateBuilder()
+        .property(WorkflowResourceProvider.WORKFLOW_CLUSTER_NAME_PROPERTY_ID)
+        .equals("Cluster100").toPredicate();
+    Set<Resource> resources = provider.getResources(request, predicate);
+
+    Assert.assertEquals(3, resources.size());
+    Set<String> names = new HashSet<String>();
+    for (Resource resource : resources) {
+      String clusterName = (String) resource
+          .getPropertyValue(WorkflowResourceProvider.WORKFLOW_CLUSTER_NAME_PROPERTY_ID);
+      Assert.assertEquals("Cluster100", clusterName);
+      names.add((String) resource
+          .getPropertyValue(WorkflowResourceProvider.WORKFLOW_ID_PROPERTY_ID));
+    }
+    // Make sure that all of the response objects got moved into resources
+    for (Resource resource : expected) {
+      Assert.assertTrue(names.contains(resource
+          .getPropertyValue(WorkflowResourceProvider.WORKFLOW_ID_PROPERTY_ID)));
+    }
+
+    verify(workflowFetcher);
+  }
+
+  @Test
+  public void testWorkflowFetcher() throws SystemException,
+      UnsupportedPropertyException, NoSuchResourceException,
+      NoSuchParentResourceException {
+    Set<String> requestedIds = new HashSet<String>();
+    requestedIds.add(WorkflowResourceProvider.WORKFLOW_ID_PROPERTY_ID);
+
+    Map<Resource.Type,String> keyPropertyIds = PropertyHelper
+        .getKeyPropertyIds(Resource.Type.Workflow);
+    ResourceProvider provider = new TestWorkflowResourceProvider(requestedIds,
+        keyPropertyIds);
+
+    Request request = PropertyHelper.getReadRequest(requestedIds);
+    Predicate predicate = new PredicateBuilder()
+        .property(WorkflowResourceProvider.WORKFLOW_ID_PROPERTY_ID)
+        .equals("workflow1").toPredicate();
+    Set<Resource> resources = provider.getResources(request, predicate);
+
+    Assert.assertEquals(1, resources.size());
+    for (Resource resource : resources) {
+      String workflowId = (String) resource
+          .getPropertyValue(WorkflowResourceProvider.WORKFLOW_ID_PROPERTY_ID);
+      Assert.assertEquals("workflow1", workflowId);
+    }
+  }
+
+  private static Resource createWorkflowResponse(String clusterName,
+      String workflowId) {
+    Resource r = new ResourceImpl(Resource.Type.Workflow);
+    r.setProperty(WorkflowResourceProvider.WORKFLOW_CLUSTER_NAME_PROPERTY_ID,
+        clusterName);
+    r.setProperty(WorkflowResourceProvider.WORKFLOW_ID_PROPERTY_ID, workflowId);
+    return r;
+  }
+
+  private static class TestWorkflowResourceProvider extends
+      WorkflowResourceProvider {
+    protected TestWorkflowResourceProvider(Set<String> propertyIds,
+        Map<Type,String> keyPropertyIds) {
+      super(propertyIds, keyPropertyIds, null);
+      this.workflowFetcher = new TestWorkflowFetcher();
+    }
+
+    private class TestWorkflowFetcher extends PostgresWorkflowFetcher {
+      ResultSet rs = null;
+
+      public TestWorkflowFetcher() {
+        super((ConnectionFactory) null);
+      }
+
+      @Override
+      protected ResultSet getResultSet(Set<String> requestedIds,
+          String workflowId) throws SQLException {
+        rs = createMock(ResultSet.class);
+        expect(rs.next()).andReturn(true).once();
+        expect(rs.getString(getDBField(WORKFLOW_ID_PROPERTY_ID).toString()))
+            .andReturn("workflow1").once();
+        expect(rs.next()).andReturn(false).once();
+        rs.close();
+        expectLastCall().once();
+        replay(rs);
+        return rs;
+      }
+
+      @Override
+      protected void close() {
+        verify(rs);
+      }
+    }
+  }
+}

Propchange: incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/WorkflowResourceProviderTest.java
------------------------------------------------------------------------------
    svn:eol-style = native