@Test public void testCreateResource() throws Exception { Capture<ArtifactEntity> createEntityCapture = newCapture(); Map<String, Object> outerMap = new TreeMap<String, Object>(); Map<String, Object> childMap = new TreeMap<String, Object>(); outerMap.put("child", childMap); childMap.put("childKey", "childValue"); Map<String, Object> child2Map = new TreeMap<String, Object>(); childMap.put("child2", child2Map); child2Map.put("child2Key", "child2Value"); Map<String, Object> child3Map = new TreeMap<String, Object>(); child2Map.put("child3", child3Map); Map<String, Object> child4Map = new TreeMap<String, Object>(); child3Map.put("child4", child4Map); child4Map.put("child4Key", "child4Value"); Set<Map<String, Object>> propertySet = new HashSet<Map<String, Object>>(); propertySet.add(outerMap); propertySet.add(child4Map); Map<String, Object> artifact_data = new TreeMap<String, Object>(); artifact_data.put("foo", "bar"); artifact_data.put("child", childMap); artifact_data.put("collection", propertySet); TreeMap<String, String> foreignKeys = new TreeMap<String, String>(); foreignKeys.put("cluster", "500"); Map<String, String> requestInfoProps = new HashMap<String, String>(); requestInfoProps.put(Request.REQUEST_INFO_BODY_PROPERTY, bodyJson); Map<String, Object> properties = new HashMap<String, Object>(); properties.put("Artifacts/artifact_name", "test-artifact"); properties.put("Artifacts/cluster_name", "test-cluster"); properties.put("artifact_data/foo", "bar"); properties.put("artifact_data/child/childKey", "childValue"); properties.put("artifact_data/child/child2/child2Key", "child2Value"); properties.put("artifact_data/child/child2/child3/child4/child4Key", "child4Value"); Collection<Object> collectionProperties = new HashSet<Object>(); properties.put("artifact_data/collection", collectionProperties); Map<String, Object> map1 = new TreeMap<String, Object>(); collectionProperties.add(map1); map1.put("foo", "bar"); map1.put("child/childKey", "childValue"); map1.put("child/child2/child2Key", "child2Value"); map1.put("child/child2/child3/child4/child4Key", "child4Value"); Map<String, Object> map2 = new TreeMap<String, Object>(); collectionProperties.add(map2); map2.put("child4Key", "child4Value"); Set<Map<String, Object>> requestProperties = Collections.singleton(properties); expect(request.getRequestInfoProperties()).andReturn(requestInfoProps).anyTimes(); expect(request.getProperties()).andReturn(requestProperties).anyTimes(); expect(controller.getClusters()).andReturn(clusters).anyTimes(); expect(clusters.getCluster("test-cluster")).andReturn(cluster).anyTimes(); expect(clusters.getClusterById(500L)).andReturn(cluster).anyTimes(); expect(cluster.getClusterId()).andReturn(500L).anyTimes(); expect(cluster.getClusterName()).andReturn("test-cluster").anyTimes(); expect(dao.findByNameAndForeignKeys(eq("test-artifact"), eq(foreignKeys))).andReturn(null).once(); dao.create(capture(createEntityCapture)); replay(dao, em, controller, request, clusters, cluster, entity, entity2); resourceProvider.createResources(request); ArtifactEntity createEntity = createEntityCapture.getValue(); assertEquals("test-artifact", createEntity.getArtifactName()); Map<String, Object> actualArtifactData = createEntity.getArtifactData(); assertEquals(artifact_data.size(), actualArtifactData.size()); assertEquals(artifact_data.get("foo"), actualArtifactData.get("foo")); assertEquals(artifact_data.get("child"), actualArtifactData.get("child")); assertEquals(artifact_data.get("collection"), new HashSet(((Collection) actualArtifactData.get("collection")))); assertEquals(foreignKeys, createEntity.getForeignKeys()); }
@Override public RequestStatus createResources(Request request) throws SystemException, UnsupportedPropertyException, ResourceAlreadyExistsException, NoSuchParentResourceException { for (Map<String, Object> properties : request.getProperties()) { createResources(getCreateCommand(properties, request.getRequestInfoProperties())); } notifyCreate(Resource.Type.Artifact, request); return getRequestStatus(null); }
ArtifactResourceProvider extends AbstractResourceProvider { @Override public RequestStatus createResources(Request request) throws SystemException, UnsupportedPropertyException, ResourceAlreadyExistsException, NoSuchParentResourceException { for (Map<String, Object> properties : request.getProperties()) { createResources(getCreateCommand(properties, request.getRequestInfoProperties())); } notifyCreate(Resource.Type.Artifact, request); return getRequestStatus(null); } }
ArtifactResourceProvider extends AbstractResourceProvider { @Override public RequestStatus createResources(Request request) throws SystemException, UnsupportedPropertyException, ResourceAlreadyExistsException, NoSuchParentResourceException { for (Map<String, Object> properties : request.getProperties()) { createResources(getCreateCommand(properties, request.getRequestInfoProperties())); } notifyCreate(Resource.Type.Artifact, request); return getRequestStatus(null); } @Inject protected  ArtifactResourceProvider(AmbariManagementController controller); }
ArtifactResourceProvider extends AbstractResourceProvider { @Override public RequestStatus createResources(Request request) throws SystemException, UnsupportedPropertyException, ResourceAlreadyExistsException, NoSuchParentResourceException { for (Map<String, Object> properties : request.getProperties()) { createResources(getCreateCommand(properties, request.getRequestInfoProperties())); } notifyCreate(Resource.Type.Artifact, request); return getRequestStatus(null); } @Inject protected  ArtifactResourceProvider(AmbariManagementController controller); @Override RequestStatus createResources(Request request); @Override Set<Resource> getResources(Request request, Predicate predicate); @Override RequestStatus updateResources(final Request request, Predicate predicate); @Override RequestStatus deleteResources(Request request, Predicate predicate); }
ArtifactResourceProvider extends AbstractResourceProvider { @Override public RequestStatus createResources(Request request) throws SystemException, UnsupportedPropertyException, ResourceAlreadyExistsException, NoSuchParentResourceException { for (Map<String, Object> properties : request.getProperties()) { createResources(getCreateCommand(properties, request.getRequestInfoProperties())); } notifyCreate(Resource.Type.Artifact, request); return getRequestStatus(null); } @Inject protected  ArtifactResourceProvider(AmbariManagementController controller); @Override RequestStatus createResources(Request request); @Override Set<Resource> getResources(Request request, Predicate predicate); @Override RequestStatus updateResources(final Request request, Predicate predicate); @Override RequestStatus deleteResources(Request request, Predicate predicate); static final String ARTIFACT_NAME_PROPERTY; static final String ARTIFACT_DATA_PROPERTY; }