/** * Removes the event panel. * * @param layout the layout */ private void removeEventPanel(final VerticalLayout layout) { if (layout.getComponentCount() > 1) layout.removeComponent(layout.getComponent(1)); }
@Test public void testVerificationPassword() { // GIVEN definition.setVerification(true); // WHEN PasswordFields field = (PasswordFields) passwordFieldFactory.createField(); // THEN assertEquals(true, field.getVerticalLayout().getComponent(1) instanceof PasswordField); assertEquals(true, field.getVerticalLayout().getComponent(2) instanceof Label); assertEquals("Please confirm", ((Label) field.getVerticalLayout().getComponent(2)).getValue().toString()); assertEquals(true, field.getVerticalLayout().getComponent(3) instanceof PasswordField); }
@Test(expected = InvalidValueException.class) public void testVerificationDoNotMatch() { // GIVEN definition.setVerification(true); PasswordFields field = (PasswordFields) passwordFieldFactory.createField(); ((PasswordField) field.getVerticalLayout().getComponent(1)).setValue("aa"); ((PasswordField) field.getVerticalLayout().getComponent(3)).setValue("axa"); // WHEN field.validate(); // THEN }
/** * Scroll into view. */ private void scrollIntoView() { final VerticalLayout layout = (VerticalLayout) getContent(); if (getUI() != null && layout.getComponentCount() > 0) getUI().scrollIntoView(layout.getComponent(layout.getComponentCount() - 1)); }
@Test public void doNotKeepEmptyProperties() throws Exception { // GIVEN SwitchableFieldDefinition definition = switchableFieldDefinition("switchable"); Node node = session.getRootNode().addNode("node"); node.setProperty("switchable", "t2"); node.setProperty("switchablet1", ""); node.setProperty("switchablet2", "boo2"); node.getSession().save(); JcrNodeAdapter nodeAdapter = new JcrNodeAdapter(node); SwitchableFieldFactory<SwitchableFieldDefinition> factory = new SwitchableFieldFactory<>(definition, nodeAdapter, fieldFactoryFactory, componentProvider, i18nAuthoringSupport); SwitchableField field = (SwitchableField) factory.createField(); Iterator<Component> componentIterator = field.iterator(); // CustomField#getContent is lazy, we trigger it via ComponentIterator#next() VerticalLayout layout = (VerticalLayout) componentIterator.next(); TextField t2 = (TextField) layout.getComponent(2); // WHEN enterText(t2, ""); nodeAdapter.applyChanges(); // THEN assertThat(node, hasProperty("switchable", "t2")); assertThat(node, not(hasProperty("switchablet1"))); assertThat(node, not(hasProperty("switchablet2"))); }
@Test(expected = InvalidValueException.class) public void currentPasswordVerificationDoesNotMatch() { // GIVEN definition.setVerification(false); definition.setVerificationCurrentPassword(true); PasswordFields field = (PasswordFields) passwordFieldFactory.createField(); ((PasswordField) field.getVerticalLayout().getComponent(1)).setValue("password"); ((PasswordField) field.getVerticalLayout().getComponent(3)).setValue("password"); when(user.getPassword()).thenReturn(SecurityUtil.getBCrypt("anotherPassword")); // WHEN field.validate(); // THEN // exception is thrown }
@Test(expected = InvalidValueException.class) public void currentPasswordVerificationWithEmptyFieldValue() { // GIVEN definition.setVerification(false); definition.setVerificationCurrentPassword(true); PasswordFields field = (PasswordFields) passwordFieldFactory.createField(); ((PasswordField) field.getVerticalLayout().getComponent(1)).setValue(""); ((PasswordField) field.getVerticalLayout().getComponent(3)).setValue("password"); when(user.getPassword()).thenReturn(SecurityUtil.getBCrypt("password")); // WHEN field.validate(); // THEN // exception is thrown }
@Test public void testVerificationMatch() { // GIVEN definition.setVerification(true); PasswordFields field = (PasswordFields) passwordFieldFactory.createField(); ((PasswordField) field.getVerticalLayout().getComponent(1)).setValue("aa"); ((PasswordField) field.getVerticalLayout().getComponent(3)).setValue("aa"); // WHEN field.validate(); // THEN assertEquals(true, field.isValid()); }
@Test public void discardUnselectedOptions() throws Exception { // GIVEN SwitchableFieldDefinition definition = switchableFieldDefinition("switchable"); Node node = session.getRootNode().addNode("node"); JcrNodeAdapter nodeAdapter = new JcrNodeAdapter(node); SwitchableFieldFactory<SwitchableFieldDefinition> factory = new SwitchableFieldFactory<>(definition, nodeAdapter, fieldFactoryFactory, componentProvider, i18nAuthoringSupport); SwitchableField field = (SwitchableField) factory.createField(); Iterator<Component> componentIterator = field.iterator(); // CustomField#getContent is lazy, we trigger it via ComponentIterator#next() VerticalLayout layout = (VerticalLayout) componentIterator.next(); OptionGroup options = (OptionGroup) layout.getComponent(0); TextField t1 = (TextField) layout.getComponent(1); TextField t2 = (TextField) layout.getComponent(2); // WHEN options.setValue("t1"); enterText(t1, "v1"); options.setValue("t2"); enterText(t2, "v2"); nodeAdapter.applyChanges(); // THEN assertThat(node, hasProperty("switchable", "t2")); assertThat(node, hasProperty("switchablet2", "v2")); assertThat(node, not(hasProperty("switchablet1"))); }
@Test public void currentPasswordVerificationMatches() { // GIVEN definition.setVerification(false); definition.setVerificationCurrentPassword(true); PasswordFields field = (PasswordFields) passwordFieldFactory.createField(); ((PasswordField) field.getVerticalLayout().getComponent(1)).setValue("password"); when(user.getPassword()).thenReturn(SecurityUtil.getBCrypt("password")); // WHEN field.validate(); // THEN assertTrue(field.isValid()); }