2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2018 Amdocs
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.logging.demo;
23 import static org.junit.Assert.*;
27 import javax.servlet.http.HttpServletRequest;
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;
39 public class ApplicationServiceTest {
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);
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"));
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);
77 public final void testJAXRSFramework() {
78 // primarily for code coverage
79 RestApplication app = new RestApplication();
81 Set<Class<?>> classes = app.getClasses();
82 Assert.notNull(classes);
83 Assert.isTrue(classes.size() > 1);
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
105 joinPoint.getSignature();
106 joinPoint.getSourceLocation();
107 joinPoint.getStaticPart();
109 joinPoint.toLongString();
110 joinPoint.toShortString();