@Test public void testComponentSpec() { em.getTransaction().begin(); long time = System.currentTimeMillis(); final Map<String,String> initialViews = Collections.singletonMap("v1", "v1value"); Tag t1 = new Tag(); t1.setTagId("tag1"); Tag t2 = new Tag(); t2.setTagId("tag2"); final List<Tag> tags = Arrays.asList(t1, t2); for (Tag t:tags) { em.persist(t); } ComponentSpec cs = createComponentSpec(Long.toString(time), "chris", "cs", "type1", "chris",tags, initialViews); em.persist(cs); ComponentSpec cs1 = createComponentSpec(Long.toString(time+1), "chris", "cs1", "type2", "chris", Collections.<Tag>emptyList(), initialViews); em.persist(cs1); cs.getReferencedComponents().add(cs1); em.getTransaction().commit(); em.clear(); cs = em.find(ComponentSpec.class, Long.toString(time)); checkComponentSpec(cs,"chris","type1", "chris", "cs", tags, initialViews); Assert.assertEquals(cs.getReferencedComponents().size(), 1); Assert.assertEquals(cs.getReferencedComponents().iterator().next().getComponentId(), Long.toString(time+1)); checkComponentSpec(cs.getReferencedComponents().iterator().next(), "chris", "type2", "chris", "cs1",Collections.<Tag>emptyList(), initialViews); em.getTransaction().begin(); ComponentSpec cs2 = createComponentSpec(Long.toString(time+2), "chris", "cs2", "type3", "chris", Collections.<Tag>emptyList(), Collections.<String,String>emptyMap()); cs = em.find(ComponentSpec.class, Long.toString(time)); cs.getReferencedComponents().add(0, cs2); em.getTransaction().commit(); em.clear(); Assert.assertNotNull(em.find(ComponentSpec.class, Long.toString(time+2))); cs = em.find(ComponentSpec.class, Long.toString(time)); Assert.assertEquals(cs.getReferencedComponents().size(), 2); Iterator<ComponentSpec> it = cs.getReferencedComponents().iterator(); Assert.assertEquals(it.next().getComponentId(), Long.toString(time+2)); Assert.assertEquals(it.next().getComponentId(), Long.toString(time+1)); }
public ComponentSpec() { }
ComponentSpec implements Serializable { public ComponentSpec() { } }
ComponentSpec implements Serializable { public ComponentSpec() { } ComponentSpec(); }
ComponentSpec implements Serializable { public ComponentSpec() { } ComponentSpec(); @PrePersist void initializePriorToDatabaseAdd(); String getComponentId(); void setComponentId(String componentId); String getComponentName(); void setComponentName(String componentName); String getCreatorUserId(); void setCreatorUserId(String creatorUserId); String getOwner(); void setOwner(String owner); Date getDateCreated(); String getExternalKey(); void setExternalKey(String externalKey); Date getLastModified(); void setLastModified(Date lastModified); String getComponentType(); void setComponentType(String componentType); String getModelInfo(); void setModelInfo(String modelInfo); void setObjVersion(int versionNumber); int getObjVersion(); Collection<ViewState> getViewStateCollection(); void setViewStateCollection(Collection<ViewState> viewStateCollection); List<ComponentSpec> getReferencedComponents(); void setReferencedComponents(List<ComponentSpec> componentRelationshipCollection); Collection<TagAssociation> getTagAssociationCollection(); void setTagAssociationCollection(Collection<TagAssociation> tagAssociationCollection); @Override int hashCode(); @Override boolean equals(Object object); @Override String toString(); }
ComponentSpec implements Serializable { public ComponentSpec() { } ComponentSpec(); @PrePersist void initializePriorToDatabaseAdd(); String getComponentId(); void setComponentId(String componentId); String getComponentName(); void setComponentName(String componentName); String getCreatorUserId(); void setCreatorUserId(String creatorUserId); String getOwner(); void setOwner(String owner); Date getDateCreated(); String getExternalKey(); void setExternalKey(String externalKey); Date getLastModified(); void setLastModified(Date lastModified); String getComponentType(); void setComponentType(String componentType); String getModelInfo(); void setModelInfo(String modelInfo); void setObjVersion(int versionNumber); int getObjVersion(); Collection<ViewState> getViewStateCollection(); void setViewStateCollection(Collection<ViewState> viewStateCollection); List<ComponentSpec> getReferencedComponents(); void setReferencedComponents(List<ComponentSpec> componentRelationshipCollection); Collection<TagAssociation> getTagAssociationCollection(); void setTagAssociationCollection(Collection<TagAssociation> tagAssociationCollection); @Override int hashCode(); @Override boolean equals(Object object); @Override String toString();  }