a263a1f1a09af82cc9149c9cdd54cc449f8b5ea7
[logging-analytics.git] / reference / logging-demo / src / test / java / org / onap / logging / demo / ApplicationServiceTest.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.logging
4  * ================================================================================
5  * Copyright © 2018 Amdocs
6  * All rights reserved.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *    http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  */
21 package org.onap.logging.demo;
22
23 import static org.junit.Assert.*;
24
25 import java.util.Set;
26
27 import javax.servlet.http.HttpServletRequest;
28
29 import org.junit.Test;
30 import org.onap.demo.logging.test.JoinPointMock;
31 import org.onap.demo.logging.ApplicationService;
32 import org.onap.demo.logging.LoggingAspect;
33 import org.onap.demo.logging.RestApplication;
34 import org.onap.demo.logging.RestHealthServiceImpl;
35 import org.onap.demo.logging.RestServiceImpl;
36 import org.springframework.mock.web.MockHttpServletRequest;
37 import org.springframework.util.Assert;
38
39 public class ApplicationServiceTest {
40
41     @Test
42     public final void testHealth() {
43         ApplicationService service = new ApplicationService();
44         Assert.notNull(service);
45         HttpServletRequest servletRequest = new MockHttpServletRequest();
46         Assert.notNull(servletRequest);
47         boolean health = service.health(servletRequest);
48         Assert.isTrue(health);
49     }
50
51     @Test
52     public final void testRestEndpointCoverageForRestHealthServiceImpl() {
53         // primarily for code coverage
54         RestHealthServiceImpl service = new RestHealthServiceImpl();
55         Assert.notNull(service);
56         ApplicationService appService = new ApplicationService();
57         Assert.notNull(appService);
58         service.setApplicationService(appService);
59         String health = service.getHealth();
60         Assert.notNull(health);
61         Assert.isTrue(health.equalsIgnoreCase("true"));
62     }
63     
64     @Test
65     public final void testRestEndpointCoverageForRestServiceImpl() {
66         // primarily for code coverage
67         RestServiceImpl service = new RestServiceImpl();
68         Assert.notNull(service);
69         ApplicationService appService = new ApplicationService();
70         Assert.notNull(appService);
71         service.setApplicationService(appService);
72         String health = service.getTest();
73         Assert.notNull(health);
74     }
75     
76     @Test
77     public final void testJAXRSFramework() {
78         // primarily for code coverage
79         RestApplication app = new RestApplication();
80         Assert.notNull(app);
81         Set<Class<?>> classes = app.getClasses();
82         Assert.notNull(classes);
83         Assert.isTrue(classes.size() > 1);
84     }
85     
86     @Test
87     public final void testLoggingAspect() {
88         // primarily for code coverage
89         LoggingAspect aspect = new LoggingAspect();
90         Assert.notNull(aspect);
91         JoinPointMock joinPoint = new JoinPointMock();
92         ApplicationService appService = new ApplicationService();
93         Assert.notNull(appService);
94         joinPoint.setTarget(appService.getClass());
95         joinPoint.getTarget();
96         HttpServletRequest servletRequest = new MockHttpServletRequest();
97         Assert.notNull(servletRequest);
98         HttpServletRequest[] args = new HttpServletRequest[1];
99         args[0] = servletRequest;
100         joinPoint.setArgs(args);
101         aspect.logAfter(joinPoint);
102         aspect.logBefore(joinPoint);
103         // cover mock joinpoint - expecting null as only target and args needs to be implemented
104         joinPoint.getKind();
105         joinPoint.getSignature();
106         joinPoint.getSourceLocation();
107         joinPoint.getStaticPart();
108         joinPoint.getThis();
109         joinPoint.toLongString();
110         joinPoint.toShortString();
111     }
112 }