/** * @see Obs#setFormField(String,String) */ @Test public void setFormField_shouldSetTheUnderlyingFormNamespaceAndPathInTheCorrectPattern() throws Exception { final String ns = "my ns"; final String path = "my path"; Obs obs = new Obs(); obs.setFormField(ns, path); java.lang.reflect.Field formNamespaceAndPathProperty = Obs.class.getDeclaredField("formNamespaceAndPath"); formNamespaceAndPathProperty.setAccessible(true); Assert.assertEquals(ns + FORM_NAMESPACE_PATH_SEPARATOR + path, formNamespaceAndPathProperty.get(obs)); }
/** * @see Obs#setFormField(String,String) */ @Test(expected = APIException.class) public void setFormField_shouldRejectANamepaceAndPathCombinationLongerThanTheMaxLength() throws Exception { StringBuilder nsBuffer = new StringBuilder(125); for (int i = 0; i < 125; i++) { nsBuffer.append("n"); } for (int i = 0; i < 130; i++) { nsBuffer.append("p"); } final String ns = nsBuffer.toString(); final String path = ""; Obs obs = new Obs(); obs.setFormField(ns, path); }
/** * @see Obs#setFormField(String,String) */ @Test(expected = APIException.class) public void setFormField_shouldRejectANamepaceContainingTheSeparator() throws Exception { final String ns = "my ns" + FORM_NAMESPACE_PATH_SEPARATOR; Obs obs = new Obs(); obs.setFormField(ns, ""); }
/** * @see Obs#setFormField(String,String) */ @Test(expected = APIException.class) public void setFormField_shouldRejectAPathContainingTheSeparator() throws Exception { final String path = FORM_NAMESPACE_PATH_SEPARATOR + "my path"; Obs obs = new Obs(); obs.setFormField("", path); }
/** * @see Obs#getFormFieldNamespace() */ @Test public void getFormFieldNamespace_shouldReturnTheCorrectNamespaceForAFormFieldWithAPath() throws Exception { final String ns = "my ns"; final String path = "my path"; Obs obs = new Obs(); obs.setFormField(ns, path); Assert.assertEquals(ns, obs.getFormFieldNamespace()); }
/** * @see Obs#getFormFieldPath() */ @Test public void getFormFieldPath_shouldReturnNullIfThePathIsNotSpecified() throws Exception { Obs obs = new Obs(); obs.setFormField("my ns", ""); Assert.assertNull(obs.getFormFieldPath()); }
/** * @see Obs#getFormFieldPath() */ @Test public void getFormFieldPath_shouldReturnTheCorrectPathForAFormFieldWithANamespace() throws Exception { final String ns = "my ns"; final String path = "my path"; Obs obs = new Obs(); obs.setFormField(ns, path); Assert.assertEquals(path, obs.getFormFieldPath()); }
/** * @see Obs#getFormFieldPath() */ @Test public void getFormFieldPath_shouldReturnThePathForAFormFieldThatHasNoNamespace() throws Exception { final String path = "my path"; Obs obs = new Obs(); obs.setFormField("", path); Assert.assertEquals(path, obs.getFormFieldPath()); }
/** * @see Obs#getFormFieldNamespace() */ @Test public void getFormFieldNamespace_shouldReturnNullIfTheNamespaceIsNotSpecified() throws Exception { Obs obs = new Obs(); obs.setFormField("", "my path"); Assert.assertNull(obs.getFormFieldNamespace()); }
/** * @see Obs#getFormFieldNamespace() */ @Test public void getFormFieldNamespace_shouldReturnTheNamespaceForAFormFieldThatHasNoPath() throws Exception { final String ns = "my ns"; Obs obs = new Obs(); obs.setFormField(ns, null); Assert.assertEquals(ns, obs.getFormFieldNamespace()); }
/** * @see Obs#setFormField(String,String) */ @Test public void setFormField_shouldNotMarkTheObsAsDirtyWhenTheValueHasNotBeenChanged() throws Exception { Obs obs = createObs(3); obs.setFormField(obs.getFormFieldNamespace(), obs.getFormFieldPath()); assertFalse(obs.isDirty()); }
/** * @see Obs#setFormField(String,String) */ @Test public void setFormField_shouldMarkTheObsAsDirtyWhenTheValueIsChangedFromANonNullToANullValue() throws Exception { Obs obs = new Obs(2); obs.setFormField("someNameSpace", "somePath"); resetObs(obs); assertFalse(obs.isDirty()); assertNotNull(obs.getFormFieldNamespace()); assertNotNull(obs.getFormFieldPath()); obs.setFormField(null, null); assertTrue(obs.isDirty()); }
/** * @see Obs#setFormField(String,String) */ @Test public void setFormField_shouldMarkTheObsAsDirtyWhenTheValueIsChangedFromANullToANonNullValue() throws Exception { Obs obs = new Obs(5); assertNull(obs.getFormFieldNamespace()); assertNull(obs.getFormFieldPath()); obs.setFormField("someNameSpace", "somePath"); assertTrue(obs.isDirty()); }
/** * @see Obs#setFormField(String,String) */ @Test public void setFormField_shouldMarkTheObsAsDirtyWhenTheValueHasBeenChanged() throws Exception { Obs obs = createObs(5); final String newNameSpace = "someNameSpace"; final String newPath = "somePath"; assertNotEquals(newPath, obs.getFormFieldNamespace()); assertNotEquals(newNameSpace, obs.getFormFieldPath()); obs.setFormField(newNameSpace, newPath); assertTrue(obs.isDirty()); }
newObs.setFormField(obsToCopy.getFormFieldNamespace(),obsToCopy.getFormFieldPath());