1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.syncope.fit.console;
20
21 import static org.junit.jupiter.api.Assertions.assertNotNull;
22
23 import java.lang.reflect.InvocationTargetException;
24 import org.apache.syncope.client.console.pages.Logs;
25 import org.apache.syncope.client.ui.commons.Constants;
26 import org.apache.wicket.Component;
27 import org.apache.wicket.core.util.lang.PropertyResolver;
28 import org.apache.wicket.markup.html.WebMarkupContainer;
29 import org.apache.wicket.markup.html.form.DropDownChoice;
30 import org.apache.wicket.markup.html.form.Form;
31 import org.apache.wicket.markup.html.list.ListItem;
32 import org.apache.wicket.util.visit.IVisit;
33 import org.junit.jupiter.api.BeforeEach;
34 import org.junit.jupiter.api.Test;
35
36 public class LogsITCase extends AbstractConsoleITCase {
37
38 private static final String CONTAINER_PATH = "body:content:tabbedPanel:panel:loggerContainer";
39
40 @BeforeEach
41 public void login() {
42 doLogin(ADMIN_UNAME, ADMIN_PWD);
43 TESTER.clickLink("body:configurationLI:configurationUL:logsLI:logs", false);
44 TESTER.assertRenderedPage(Logs.class);
45 }
46
47 @Test
48 public void readLogs() {
49 TESTER.clickLink("body:content:tabbedPanel:tabs-container:tabs:0:link");
50 TESTER.assertComponent(CONTAINER_PATH, WebMarkupContainer.class);
51
52 assertNotNull(searchLog(KEY, CONTAINER_PATH, "io.swagger"));
53 }
54
55 @Test
56 public void updateLogs() {
57 TESTER.clickLink("body:content:tabbedPanel:tabs-container:tabs:0:link");
58 TESTER.assertComponent(CONTAINER_PATH, WebMarkupContainer.class);
59
60 Component result = searchLog(KEY, CONTAINER_PATH, "io.swagger");
61 assertNotNull(result);
62
63 TESTER.getRequest().setMethod(Form.METHOD_GET);
64 TESTER.getRequest().addParameter(
65 result.getPageRelativePath() + ":fields:1:field:dropDownChoiceField", "6");
66 TESTER.assertComponent(
67 result.getPageRelativePath() + ":fields:1:field:dropDownChoiceField", DropDownChoice.class);
68 TESTER.executeAjaxEvent(
69 result.getPageRelativePath() + ":fields:1:field:dropDownChoiceField", Constants.ON_CHANGE);
70
71 assertSuccessMessage();
72 }
73
74 private static Component searchLog(final String property, final String searchPath, final String key) {
75 Component component = TESTER.getComponentFromLastRenderedPage(searchPath);
76
77 Component result = component.getPage().
78 visitChildren(ListItem.class, (final ListItem<?> object, final IVisit<Component> visit) -> {
79 try {
80 if ("LoggerConf".equals(object.getModelObject().getClass().getSimpleName())
81 && PropertyResolver.getPropertyGetter(property, object.getModelObject()).
82 invoke(object.getModelObject()).equals(key)) {
83
84 visit.stop(object);
85 }
86 } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) {
87 LOG.error("Error invoke method", ex);
88 }
89 });
90 return result;
91 }
92 }