View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
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  }