Skip to content

Commit

Permalink
Improve ReferTo logging when reference does not exist (#174)
Browse files Browse the repository at this point in the history
  • Loading branch information
jkosternl authored Feb 21, 2024
1 parent f2a9519 commit 19f1186
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public FrankMethod valueOf(FrankMethod method) {
} else {
FrankMethod referred = getReferredMethod(resultAsString, method);
if(referred == null) {
log.error("Referred method [{}] does not exist", resultAsString);
log.error("Referred method [{}] does not exist, as specified at location: [{}]", resultAsString, method);
} else {
return referred;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2021 WeAreFrank!
Copyright 2021-2024 WeAreFrank!
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -15,14 +15,16 @@
*/
package org.frankframework.frankdoc.model;

import org.frankframework.frankdoc.TestAppender;
import org.frankframework.frankdoc.feature.Reference;
import org.frankframework.frankdoc.wrapper.FrankClassRepository;
import org.frankframework.frankdoc.wrapper.FrankDocException;
import org.frankframework.frankdoc.wrapper.FrankMethod;
import org.frankframework.frankdoc.wrapper.TestUtil;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand All @@ -43,8 +45,8 @@ public class FrankDocModelTest {
private static final String LISTENER = SIMPLE + ".IListener";
private static final String SIMPLE_PARENT = SIMPLE + ".ListenerParent";
private static final String SIMPLE_CHILD = SIMPLE + ".ListenerChild";
private static final String SIMPLE_GRNAD_CHILD = SIMPLE + ".ListenerGrandChild";
private static final String SIMPLE_GRNAD_PARENT = SIMPLE + ".AbstractGrandParent";
private static final String SIMPLE_GRAND_CHILD = SIMPLE + ".ListenerGrandChild";
private static final String SIMPLE_GRAND_PARENT = SIMPLE + ".AbstractGrandParent";
private static final String FOR_XSD_ELEMENT_NAME_TEST = SIMPLE + ".ParentListener";

private static final String IBISDOCREF = "org.frankframework.frankdoc.testtarget.ibisdocref";
Expand Down Expand Up @@ -91,7 +93,7 @@ private void checkModelTypes(ElementType actualListener, ElementType actualChild
assertEquals(4, listenerMembers.size());
assertTrue(membersContain(listenerMembers, SIMPLE_PARENT));
assertTrue(membersContain(listenerMembers, SIMPLE_CHILD));
assertTrue(membersContain(listenerMembers, SIMPLE_GRNAD_CHILD));
assertTrue(membersContain(listenerMembers, SIMPLE_GRAND_CHILD));
List<FrankElement> childMembers = actualChild.getMembers();
assertEquals(1, childMembers.size());
assertTrue(membersContain(childMembers, SIMPLE_CHILD));
Expand Down Expand Up @@ -125,7 +127,7 @@ public void whenTypeRequestedTwiceThenSameInstanceReturned() throws FrankDocExce
public void whenChildElementAddedBeforeParentThenCorrectModel() throws FrankDocException {
FrankElement child = instance.findOrCreateFrankElement(SIMPLE_CHILD);
FrankElement parent = instance.findOrCreateFrankElement(SIMPLE_PARENT);
instance.findOrCreateFrankElement(SIMPLE_GRNAD_CHILD);
instance.findOrCreateFrankElement(SIMPLE_GRAND_CHILD);
instance.setOverriddenFrom();
checkModelAfterChildAndParentAdded(parent, child);
}
Expand All @@ -134,7 +136,7 @@ public void whenChildElementAddedBeforeParentThenCorrectModel() throws FrankDocE
public void whenParentElementAddedBeforeChildThenCorrectModel() throws FrankDocException {
FrankElement parent = instance.findOrCreateFrankElement(SIMPLE_PARENT);
FrankElement child = instance.findOrCreateFrankElement(SIMPLE_CHILD);
instance.findOrCreateFrankElement(SIMPLE_GRNAD_CHILD);
instance.findOrCreateFrankElement(SIMPLE_GRAND_CHILD);
instance.setOverriddenFrom();
checkModelAfterChildAndParentAdded(parent, child);
}
Expand All @@ -145,7 +147,7 @@ private void checkModelAfterChildAndParentAdded(FrankElement actualParent, Frank
assertTrue(actualAllElements.containsKey(actualChild.getFullName()));
assertSame(actualAllElements.get(actualParent.getFullName()), actualParent);
assertSame(actualAllElements.get(actualChild.getFullName()), actualChild);
FrankElement actualGrandParent = actualAllElements.get(SIMPLE_GRNAD_PARENT);
FrankElement actualGrandParent = actualAllElements.get(SIMPLE_GRAND_PARENT);
assertTrue(actualGrandParent.isAbstract());
FrankElement actualObject = actualAllElements.get("java.lang.Object");
assertNull(actualObject.getParent());
Expand Down Expand Up @@ -178,8 +180,8 @@ private void checkModelAfterChildAndParentAdded(FrankElement actualParent, Frank
actualInheritedAttribute = findAttribute(actualChild, "inheritedAttribute");
assertEquals("inheritedAttribute", actualInheritedAttribute.getName());
assertSame(actualParent, actualInheritedAttribute.getOverriddenFrom());
FrankElement actualGrandChild = actualAllElements.get(SIMPLE_GRNAD_CHILD);
assertEquals(SIMPLE_GRNAD_CHILD, actualGrandChild.getFullName());
FrankElement actualGrandChild = actualAllElements.get(SIMPLE_GRAND_CHILD);
assertEquals(SIMPLE_GRAND_CHILD, actualGrandChild.getFullName());
assertEquals(1, actualGrandChild.getAttributes(ALL_NOT_EXCLUDED).size());
actualInheritedAttribute = actualGrandChild.getAttributes(ALL_NOT_EXCLUDED).get(0);
assertEquals("inheritedAttribute", actualInheritedAttribute.getName());
Expand Down Expand Up @@ -520,6 +522,20 @@ public void testReferTo() throws Exception {
assertEquals("setReferToInheritedDescription description", actual.getDescription());
}

@Test
public void testReferToMissingMethod() throws Exception {
TestAppender appender = TestAppender.newBuilder().build();
TestAppender.addToRootLogger(appender);
try {
Reference reference = new Reference(classRepository);
FrankMethod targetMethod = Arrays.stream(classRepository.findClass(REFERRER).getDeclaredMethods()).filter(frankMethod -> frankMethod.getName().equals("doesNotExistsMethod")).findFirst().get();
reference.valueOf(targetMethod);
appender.assertLogged("Referred method [org.frankframework.frankdoc.testtarget.ibisdocref.ChildTargetParameterized] does not exist, as specified at location: [Referrer.doesNotExistsMethod]");
} finally {
TestAppender.removeAppender(appender);
}
}

@Test
public void testReferToWithParameterizedTargetClass() throws Exception {
FrankAttribute actual = checkIbisdocrefInvestigatedFrankAttribute("referToParameterizedType");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,8 @@ public void setReferToInheritedDescription(String value) {
@ReferTo(ChildTargetParameterized.class)
public void setReferToParameterizedType(String value) {
}

@ReferTo(ChildTargetParameterized.class)
public void doesNotExistsMethod(String value) {
}
}

0 comments on commit 19f1186

Please sign in to comment.