/** * {@inheritDoc} */ @Override public PropertyPathStart getPropertyPathStart() { PropertyPathStart propertyPathStart = new PropertyPathStart(); propertyPathStart.setName(getDisplayName()); propertyPathStart.setContentType(ParameterContentType.FIELD); // create field navigation PropertyPath fieldPath = new PropertyPath(); fieldPath.setName(fieldName); addPaths(fieldPath); // connect to the start and return propertyPathStart.setPathToContinue(fieldPath); return propertyPathStart; }
@Test public void analyzeReturnValueObjectException() throws PropertyAccessException { // create initial object relation Person peter = new Person("Peter"); Person juergen = new Person("Hans"); peter.setChild(juergen); List<PropertyPathStart> propertyAccessorList = new ArrayList<PropertyPathStart>(); // valid PropertyPathStart start = new PropertyPathStart(); start.setName("return"); start.setContentType(ParameterContentType.RETURN); PropertyPath pathOne = new PropertyPath("child"); start.setPathToContinue(pathOne); propertyAccessorList.add(start); String result = propertyAccessor.getPropertyContent(start, null, null, peter, true); assertThat(result, is("n/a")); }
@Test public void analyzeReturnValueObject() throws PropertyAccessException { // create initial object relation Person peter = new Person("Peter"); Person juergen = new Person("Hans"); peter.setChild(juergen); List<PropertyPathStart> propertyAccessorList = new ArrayList<PropertyPathStart>(); // valid PropertyPathStart start = new PropertyPathStart(); start.setName("return"); start.setContentType(ParameterContentType.RETURN); PropertyPath pathOne = new PropertyPath("child"); start.setPathToContinue(pathOne); propertyAccessorList.add(start); String result = propertyAccessor.getPropertyContent(start, null, null, peter, false); assertThat(result, is("Hans")); }
@Test public void readFieldPersonName() throws PropertyAccessException { Person person = new Person(); person.setName("Dirk"); PropertyPathStart start = new PropertyPathStart(); start.setName("this"); start.setContentType(ParameterContentType.FIELD); PropertyPath path = new PropertyPath(); path.setName("name"); start.setPathToContinue(path); String result = propertyAccessor.getPropertyContent(start, person, null, resultValueMock, false); assertThat(result, is("Dirk")); Mockito.verifyZeroInteractions(resultValueMock); }
@Test public void invokeListSizeMethod() throws PropertyAccessException { // create initial object relation Person peter = new Person("Peter"); List<String> foreNames = new ArrayList<String>(); foreNames.add("blub"); foreNames.add("blub2"); foreNames.add("blub3"); peter.setForeNamesAsList(foreNames); PropertyPathStart start = new PropertyPathStart(); start.setName("this"); start.setContentType(ParameterContentType.FIELD); PropertyPath path = new PropertyPath(); path.setName("foreNamesAsList"); start.setPathToContinue(path); PropertyPath path2 = new PropertyPath(); path2.setName("size()"); path.setPathToContinue(path2); String result = propertyAccessor.getPropertyContent(start, peter, null, resultValueMock, false); assertThat(Integer.parseInt(result), is(3)); Mockito.verifyZeroInteractions(resultValueMock); }
@Test(expectedExceptions = { PropertyAccessException.class }) public void invokeForbiddenMethod() throws PropertyAccessException { // create initial object relation Person peter = new Person("Peter"); PropertyPathStart start = new PropertyPathStart(); start.setName("this"); start.setContentType(ParameterContentType.FIELD); PropertyPath path = new PropertyPath(); path.setName("getName()"); start.setPathToContinue(path); propertyAccessor.getPropertyContent(start, peter, null, resultValueMock, false); Mockito.verifyZeroInteractions(resultValueMock); }
start.setContentType(ParameterContentType.PARAM); PropertyPath pathOne = new PropertyPath("child"); start.setPathToContinue(pathOne); propertyAccessorList.add(start); start.setContentType(ParameterContentType.FIELD); pathOne = new PropertyPath("notValid"); start.setPathToContinue(pathOne); propertyAccessorList.add(start); start.setContentType(ParameterContentType.PARAM); pathOne = new PropertyPath("child"); start.setPathToContinue(pathOne); propertyAccessorList.add(start);
start.setContentType(ParameterContentType.PARAM); PropertyPath pathOne = new PropertyPath("child"); start.setPathToContinue(pathOne); propertyAccessorList.add(start); start.setContentType(ParameterContentType.FIELD); pathOne = new PropertyPath("notValid"); start.setPathToContinue(pathOne); propertyAccessorList.add(start); start.setContentType(ParameterContentType.PARAM); pathOne = new PropertyPath("child"); start.setPathToContinue(pathOne); propertyAccessorList.add(start);
@Test(expectedExceptions = { PropertyAccessException.class }) public void analyzePersonAccessException() throws PropertyAccessException { Person person = new Person(); person.setName("Dirk"); PropertyPathStart start = new PropertyPathStart(); start.setName("this"); start.setContentType(ParameterContentType.FIELD); PropertyPath path = new PropertyPath(); path.setName("surname"); start.setPathToContinue(path); // name != surname -> exception propertyAccessor.getPropertyContent(start, person, null, resultValueMock, false); Mockito.verifyZeroInteractions(resultValueMock); }
@Test public void invokeArrayLengthMethod() throws PropertyAccessException { // create initial object relation Person peter = new Person("Peter"); String[] foreNames = new String[] { "Klaus", "Uwe" }; peter.setForeNames(foreNames); PropertyPathStart start = new PropertyPathStart(); start.setName("this"); start.setContentType(ParameterContentType.FIELD); PropertyPath path = new PropertyPath(); path.setName("foreNames"); start.setPathToContinue(path); PropertyPath path2 = new PropertyPath(); path2.setName("length()"); path.setPathToContinue(path2); String result = propertyAccessor.getPropertyContent(start, peter, null, resultValueMock, false); assertThat(Integer.parseInt(result), is(2)); Mockito.verifyZeroInteractions(resultValueMock); }
@Test(expectedExceptions = { PropertyAccessException.class }) public void invokeArrayLengthMethodOnNonArray() throws PropertyAccessException { // create initial object relation Person peter = new Person("Peter"); String[] foreNames = new String[] { "Klaus", "Uwe" }; peter.setForeNames(foreNames); PropertyPathStart start = new PropertyPathStart(); start.setName("this"); start.setContentType(ParameterContentType.FIELD); PropertyPath path = new PropertyPath(); path.setName("name"); start.setPathToContinue(path); PropertyPath path2 = new PropertyPath(); path2.setName("length()"); path.setPathToContinue(path2); // must result in an Exception as name is not an array propertyAccessor.getPropertyContent(start, peter, null, resultValueMock, false); Mockito.verifyZeroInteractions(resultValueMock); }
start.setPathToContinue(pathOne);