@Test public void testCreateNewWithExistingUuid() { tester.startPage(EditProductPage.class, new PageParameters()); FormTester formTester = tester.newFormTester("productPanel:productForm"); setMandatoryFormParameters(formTester); formTester.setValue("control.uuid:uuid", shsProduct.getUuid()); formTester.submitLink("submit", false); tester.assertRenderedPage(EditProductPage.class); tester.assertComponent("productPanel:feedback", FeedbackPanel.class); tester.assertErrorMessages( "A product with the UUID " + shsProduct.getUuid() + " already exists"); }
@Override protected void beforeMethodSetup() { super.beforeMethodSetup(); ShsRouter shsRouter = mock(ShsRouter.class); when(shsRouter.getOrgId()).thenReturn("0000000000"); injector.registerBean("shsRouter", shsRouter); ProductAdminService productAdminService = mock(ProductAdminService.class); shsProduct = ObjectMother.createShsProduct(); when(productAdminService.getProduct(shsProduct.getUuid())).thenReturn(shsProduct); when(productAdminService.findAll()).thenReturn(Arrays.asList(shsProduct)); injector.registerBean("productService", productAdminService); DirectoryAdminServiceAggregator directoryAdminServiceAggregator = mock(DirectoryAdminServiceAggregator.class); Organization organization = new Organization(); organization.setOrgName("Test organization"); organization.setOrgNumber("0000000000"); when(directoryAdminServiceAggregator.getOrganizations()) .thenReturn(Arrays.asList(organization)); DirectoryAdminServiceRegistry directoryAdminServiceRegistry = mock(DirectoryAdminServiceRegistry.class); when(directoryAdminServiceRegistry.getDirectoryAdminServiceAggregator()) .thenReturn(directoryAdminServiceAggregator); injector.registerBean("directoryAdminServiceRegistry", directoryAdminServiceRegistry); productMarshaller = new ShsProductMarshaller(); }
private List<String> productsAsIdList(List<ShsProduct> products) { List<String> idList = new ArrayList<String>(products.size()); for (ShsProduct product : products) { idList.add(product.getUuid()); } return idList; }
@Test public void testRenderEditXmlView() { PageParameters pageParameters = new PageParameters(); pageParameters.set(VIEW.toString(), "xml"); pageParameters.set(EDIT_MODE.toString(), true); pageParameters.set(CURRENT_UUID.toString(), shsProduct.getUuid()); tester.startPage(EditProductPage.class, pageParameters); tester.assertNoErrorMessage(); tester.assertComponent("productPanel:feedback", FeedbackPanel.class); tester.assertComponent("productPanel:productForm", Form.class); tester.assertComponent("productPanel:productForm:uuid", HiddenField.class); tester.assertComponent("productPanel:productForm:control.xml:xml", TextArea.class); final TextArea<String> xmlField = (TextArea<String>) tester.getComponentFromLastRenderedPage("productPanel:productForm:control.xml:xml"); assertThat(xmlField.getValue(), containsString(shsProduct.getUuid())); }
@Test @SuppressWarnings("unchecked") public void testRenderEdit() { PageParameters pageParameters = new PageParameters(); pageParameters.set(CURRENT_UUID.toString(), shsProduct.getUuid()); pageParameters.set(EDIT_MODE.toString(), true); tester.startPage(EditProductPage.class, pageParameters); tester.assertRenderedPage(EditProductPage.class); tester.assertNoErrorMessage(); tester.assertComponent("productPanel:feedback", FeedbackPanel.class); tester.assertComponent("productPanel:productForm", Form.class); tester.assertComponent("productPanel:productForm:control.uuid:uuid", TextField.class); final TextField<String> uuidField = (TextField<String>) tester.getComponentFromLastRenderedPage("productPanel:productForm:control.uuid:uuid"); assertEquals(uuidField.getModelObject(), shsProduct.getUuid()); assertFalse(uuidField.isEnabled(), "uuid was not disabled when editing an existing product"); }
@Test public void testCreateNewXmlViewWithExistingProduct() { PageParameters pageParameters = new PageParameters(); pageParameters.set(VIEW.toString(), "xml"); tester.startPage(EditProductPage.class, pageParameters); FormTester formTester = tester.newFormTester("productPanel:productForm"); formTester.setValue("control.xml:xml", productMarshaller.marshal(shsProduct)); formTester.submitLink("submit", false); tester.assertRenderedPage(EditProductPage.class); tester.assertErrorMessages( "A product with the UUID " + shsProduct.getUuid() + " already exists"); }
@Test public void testSubmitInvalidXml() { PageParameters pageParameters = new PageParameters(); pageParameters.set(VIEW.toString(), "xml"); pageParameters.set(EDIT_MODE.toString(), true); pageParameters.set(CURRENT_UUID.toString(), shsProduct.getUuid()); tester.startPage(EditProductPage.class, pageParameters); FormTester formTester = tester.newFormTester("productPanel:productForm"); formTester.setValue("control.xml:xml", "Not xml"); formTester.submitLink("submit", false); tester.assertRenderedPage(EditProductPage.class); tester.assertErrorMessages("The supplied product xml is invalid"); }
@Test public void testEditProductXmlView() { PageParameters pageParameters = new PageParameters(); pageParameters.set(VIEW.toString(), "xml"); pageParameters.set(EDIT_MODE.toString(), true); pageParameters.set(CURRENT_UUID.toString(), shsProduct.getUuid()); tester.startPage(EditProductPage.class, pageParameters); FormTester formTester = tester.newFormTester("productPanel:productForm"); shsProduct.setCommonName("New common name"); formTester.setValue("control.xml:xml", productMarshaller.marshal(shsProduct)); formTester.submitLink("submit", false); tester.assertRenderedPage(ProductPage.class); tester.assertNoErrorMessage(); }
@Test public void testChangeUUIDXmlView() { PageParameters pageParameters = new PageParameters(); pageParameters.set(VIEW.toString(), "xml"); pageParameters.set(EDIT_MODE.toString(), true); pageParameters.set(CURRENT_UUID.toString(), shsProduct.getUuid()); tester.startPage(EditProductPage.class, pageParameters); FormTester formTester = tester.newFormTester("productPanel:productForm"); shsProduct.setUuid(UUID.randomUUID().toString()); formTester.setValue("control.xml:xml", productMarshaller.marshal(shsProduct)); formTester.submitLink("submit", false); tester.assertRenderedPage(EditProductPage.class); tester.assertErrorMessages( "UUID must not be updated when editing an existing product. Original uuid " + ObjectMother.DEFAULT_PRODUCT_ID); }