View Javadoc
1   /*
2    * Logback: the reliable, generic, fast and flexible logging framework.
3    * Copyright (C) 1999-2024, QOS.ch. All rights reserved.
4    *
5    * This program and the accompanying materials are dual-licensed under
6    * either the terms of the Eclipse Public License v1.0 as published by
7    * the Eclipse Foundation
8    *
9    *   or (per the licensee's choosing)
10   *
11   * under the terms of the GNU Lesser General Public License version 2.1
12   * as published by the Free Software Foundation.
13   */
14  
15  package ch.qos.logback.core.joran.util;
16  
17  import ch.qos.logback.core.Context;
18  import ch.qos.logback.core.ContextBase;
19  import ch.qos.logback.core.joran.spi.DefaultNestedComponentRegistry;
20  import ch.qos.logback.core.joran.util.beans.BeanDescriptionCache;
21  import ch.qos.logback.core.util.AggregationType;
22  import org.junit.jupiter.api.Test;
23  
24  import java.lang.reflect.Method;
25  
26  import static org.junit.jupiter.api.Assertions.assertEquals;
27  import static org.junit.jupiter.api.Assertions.assertNotNull;
28  
29  public class AggregationAssessorTest {
30      Context context = new ContextBase();
31      AggregationAssessor aggregationAssessor = new AggregationAssessor(new BeanDescriptionCache(context), House.class);
32      DefaultNestedComponentRegistry defaultComponentRegistry = new DefaultNestedComponentRegistry();
33  
34      @Test
35      public void testgetClassNameViaImplicitRules() {
36          Class<?> compClass = aggregationAssessor.getClassNameViaImplicitRules("door", AggregationType.AS_COMPLEX_PROPERTY,
37                  defaultComponentRegistry);
38          assertEquals(Door.class, compClass);
39      }
40  
41      @Test
42      public void testgetComplexPropertyColleClassNameViaImplicitRules() {
43          Class<?> compClass = aggregationAssessor.getClassNameViaImplicitRules("window",
44                  AggregationType.AS_COMPLEX_PROPERTY_COLLECTION, defaultComponentRegistry);
45          assertEquals(Window.class, compClass);
46      }
47  
48      @Test
49      public void testDefaultClassAnnotationForLists() {
50          Method relevantMethod = aggregationAssessor.getRelevantMethod("LargeSwimmingPool",
51                  AggregationType.AS_COMPLEX_PROPERTY_COLLECTION);
52          assertNotNull(relevantMethod);
53          Class<?> spClass = aggregationAssessor.getDefaultClassNameByAnnonation("LargeSwimmingPool", relevantMethod);
54          assertEquals(LargeSwimmingPoolImpl.class, spClass);
55  
56          Class<?> classViaImplicitRules = aggregationAssessor.getClassNameViaImplicitRules("LargeSwimmingPool",
57                  AggregationType.AS_COMPLEX_PROPERTY_COLLECTION, defaultComponentRegistry);
58          assertEquals(LargeSwimmingPoolImpl.class, classViaImplicitRules);
59      }
60  
61      @Test
62      public void testDefaultClassAnnonation() {
63          Method relevantMethod = aggregationAssessor.getRelevantMethod("SwimmingPool", AggregationType.AS_COMPLEX_PROPERTY);
64          assertNotNull(relevantMethod);
65          Class<?> spClass = aggregationAssessor.getDefaultClassNameByAnnonation("SwimmingPool", relevantMethod);
66          assertEquals(SwimmingPoolImpl.class, spClass);
67  
68          Class<?> classViaImplicitRules = aggregationAssessor.getClassNameViaImplicitRules("SwimmingPool",
69                  AggregationType.AS_COMPLEX_PROPERTY, defaultComponentRegistry);
70          assertEquals(SwimmingPoolImpl.class, classViaImplicitRules);
71      }
72  
73  }