/** * Creates and persists a new attribute value list entity from the request information. * * @param request the request * @param namespaceEntity the namespace * * @return the newly created attribute value list entity */ private AttributeValueListEntity createAttributeValueListEntity(AttributeValueListCreateRequest request, NamespaceEntity namespaceEntity) { // Create a new entity. AttributeValueListEntity attributeValueListEntity = new AttributeValueListEntity(); attributeValueListEntity.setNamespace(namespaceEntity); attributeValueListEntity.setName(request.getAttributeValueListKey().getAttributeValueListName()); // Persist and return the newly created entity. return attributeValueListDao.saveAndRefresh(attributeValueListEntity); } }
/** * Creates and persists a new attribute value list entity from the request information. * * @param request the request * @param namespaceEntity the namespace * * @return the newly created attribute value list entity */ private AttributeValueListEntity createAttributeValueListEntity(AttributeValueListCreateRequest request, NamespaceEntity namespaceEntity) { // Create a new entity. AttributeValueListEntity attributeValueListEntity = new AttributeValueListEntity(); attributeValueListEntity.setNamespace(namespaceEntity); attributeValueListEntity.setName(request.getAttributeValueListKey().getAttributeValueListName()); // Persist and return the newly created entity. return attributeValueListDao.saveAndRefresh(attributeValueListEntity); } }
/** * Creates attribute value list entity and save it in the database. * * @param namespace the namespace of the attribute value list * @param attributeValueListName the name of the attribute value list * * @return the attribute value list entity */ public AttributeValueListEntity createAttributeValueListEntity(String namespace, String attributeValueListName) { // Create a namespace entity if not exists. NamespaceEntity namespaceEntity = namespaceDao.getNamespaceByCd(namespace); if (namespaceEntity == null) { namespaceEntity = namespaceDaoTestHelper.createNamespaceEntity(namespace); } // Create an attribute value list entity. AttributeValueListEntity attributeValueListEntity = new AttributeValueListEntity(); attributeValueListEntity.setNamespace(namespaceEntity); attributeValueListEntity.setName(attributeValueListName); return attributeValueListDao.saveAndRefresh(attributeValueListEntity); } }
attributeValueListEntity.setId(ATTRIBUTE_VALUE_LIST_ID); attributeValueListEntity.setNamespace(namespaceEntity); attributeValueListEntity.setName(ATTRIBUTE_VALUE_LIST_NAME);
attributeValueListEntity.setId(ATTRIBUTE_VALUE_LIST_ID); attributeValueListEntity.setNamespace(namespaceEntity); attributeValueListEntity.setName(ATTRIBUTE_VALUE_LIST_NAME); attributeValueListEntity.setAllowedAttributeValues(new ArrayList<>());
attributeValueListEntity.setId(ATTRIBUTE_VALUE_LIST_ID); attributeValueListEntity.setNamespace(namespaceEntity); attributeValueListEntity.setName(ATTRIBUTE_VALUE_LIST_NAME); attributeValueListEntity.setAllowedAttributeValues(allowedAttributeValueEntities);
@Test public void testDeleteAttributeValueList() { // Create an attribute value list key. AttributeValueListKey attributeValueListKey = new AttributeValueListKey(ATTRIBUTE_VALUE_LIST_NAMESPACE, ATTRIBUTE_VALUE_LIST_NAME); // Create a namespace entity. NamespaceEntity namespaceEntity = new NamespaceEntity(); namespaceEntity.setCode(ATTRIBUTE_VALUE_LIST_NAMESPACE); // Create an attribute value list entity. AttributeValueListEntity attributeValueListEntity = new AttributeValueListEntity(); attributeValueListEntity.setId(ATTRIBUTE_VALUE_LIST_ID); attributeValueListEntity.setNamespace(namespaceEntity); attributeValueListEntity.setName(ATTRIBUTE_VALUE_LIST_NAME); // Mock calls to external methods. when(attributeValueListDaoHelper.getAttributeValueListEntity(attributeValueListKey)).thenReturn(attributeValueListEntity); when(attributeValueListDaoHelper.createAttributeValueListFromEntity(attributeValueListEntity)).thenCallRealMethod(); // Call the method under test. AttributeValueList result = attributeValueListService.deleteAttributeValueList(attributeValueListKey); // Verify the external calls. verify(attributeValueListHelper).validateAttributeValueListKey(attributeValueListKey); verify(attributeValueListDaoHelper).getAttributeValueListEntity(attributeValueListKey); verify(attributeValueListDao).delete(attributeValueListEntity); verify(attributeValueListDaoHelper).createAttributeValueListFromEntity(attributeValueListEntity); verifyNoMoreInteractionsHelper(); // Validate the result. assertEquals(new AttributeValueList(ATTRIBUTE_VALUE_LIST_ID, attributeValueListKey), result); }
@Test public void testGetAttributeValueList() { // Create an attribute value list key. AttributeValueListKey attributeValueListKey = new AttributeValueListKey(ATTRIBUTE_VALUE_LIST_NAMESPACE, ATTRIBUTE_VALUE_LIST_NAME); // Create a namespace entity. NamespaceEntity namespaceEntity = new NamespaceEntity(); namespaceEntity.setCode(ATTRIBUTE_VALUE_LIST_NAMESPACE); // Create an attribute value list entity. AttributeValueListEntity attributeValueListEntity = new AttributeValueListEntity(); attributeValueListEntity.setId(ATTRIBUTE_VALUE_LIST_ID); attributeValueListEntity.setNamespace(namespaceEntity); attributeValueListEntity.setName(ATTRIBUTE_VALUE_LIST_NAME); // Mock calls to external methods. when(attributeValueListDaoHelper.getAttributeValueListEntity(attributeValueListKey)).thenReturn(attributeValueListEntity); when(attributeValueListDaoHelper.createAttributeValueListFromEntity(attributeValueListEntity)).thenCallRealMethod(); // Call the method under test. AttributeValueList result = attributeValueListService.getAttributeValueList(attributeValueListKey); // Verify the external calls. verify(attributeValueListHelper).validateAttributeValueListKey(attributeValueListKey); verify(attributeValueListDaoHelper).getAttributeValueListEntity(attributeValueListKey); verify(attributeValueListDaoHelper).createAttributeValueListFromEntity(attributeValueListEntity); verifyNoMoreInteractionsHelper(); // Validate the result. assertEquals(new AttributeValueList(ATTRIBUTE_VALUE_LIST_ID, attributeValueListKey), result); }
attributeValueListEntity.setId(ATTRIBUTE_VALUE_LIST_ID); attributeValueListEntity.setNamespace(namespaceEntity); attributeValueListEntity.setName(ATTRIBUTE_VALUE_LIST_NAME); attributeValueListEntity.setAllowedAttributeValues(new ArrayList<>());
attributeValueListEntity.setId(ATTRIBUTE_VALUE_LIST_ID); attributeValueListEntity.setNamespace(namespaceEntity); attributeValueListEntity.setName(ATTRIBUTE_VALUE_LIST_NAME); attributeValueListEntity.setAllowedAttributeValues(allowedAttributeValueEntities);
attributeValueListEntity.setId(ATTRIBUTE_VALUE_LIST_ID); attributeValueListEntity.setNamespace(namespaceEntity); attributeValueListEntity.setName(ATTRIBUTE_VALUE_LIST_NAME); attributeValueListEntity.setAllowedAttributeValues(new ArrayList<>());