blob: 3950d56a58c39fdd2daa94c8b1a0c7dfdf395e2c [file] [log] [blame]
b.janani68c55e12016-02-24 12:23:03 +05301/*
2 * Copyright 2016 Open Networking Laboratory
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package org.onosproject.yangutils.utils.io.impl;
18
b.janani68c55e12016-02-24 12:23:03 +053019import java.io.File;
b.janani68c55e12016-02-24 12:23:03 +053020import java.io.FileWriter;
21import java.io.IOException;
b.janani68c55e12016-02-24 12:23:03 +053022import java.lang.reflect.Constructor;
23import java.lang.reflect.InvocationTargetException;
24
Bharat saraswal6ef0b762016-04-05 12:45:45 +053025import org.junit.Rule;
26import org.junit.Test;
27import org.junit.rules.ExpectedException;
28import org.slf4j.Logger;
29
30import static org.apache.commons.io.FileUtils.contentEquals;
31import static org.hamcrest.core.Is.is;
32import static org.hamcrest.core.IsNot.not;
33import static org.junit.Assert.assertThat;
34import static org.onosproject.yangutils.utils.io.impl.CopyrightHeader.getCopyrightHeader;
35import static org.slf4j.LoggerFactory.getLogger;
36
b.janani68c55e12016-02-24 12:23:03 +053037/**
38 * Unit Tests for the CopyrightHeader contents.
39 */
40public final class CopyrightHeaderTest {
41
42 private final Logger log = getLogger(getClass());
43
44 @Rule
45 public ExpectedException thrown = ExpectedException.none();
46
47 /**
48 * Unit test for testing private constructor.
49 *
Vinod Kumar S38046502016-03-23 15:30:27 +053050 * @throws SecurityException if any security violation is observed
51 * @throws NoSuchMethodException if when the method is not found
52 * @throws IllegalArgumentException if there is illegal argument found
53 * @throws InstantiationException if instantiation is provoked for the private constructor
54 * @throws IllegalAccessException if instance is provoked or a method is provoked
55 * @throws InvocationTargetException when an exception occurs by the method or constructor
b.janani68c55e12016-02-24 12:23:03 +053056 */
57 @Test
58 public void callPrivateConstructors() throws SecurityException, NoSuchMethodException, IllegalArgumentException,
Bharat saraswal6ef0b762016-04-05 12:45:45 +053059 InstantiationException, IllegalAccessException, InvocationTargetException {
b.janani68c55e12016-02-24 12:23:03 +053060
61 Class<?>[] classesToConstruct = {CopyrightHeader.class };
62 for (Class<?> clazz : classesToConstruct) {
63 Constructor<?> constructor = clazz.getDeclaredConstructor();
64 constructor.setAccessible(true);
Bharat saraswal6ef0b762016-04-05 12:45:45 +053065 assertThat(null, not(constructor.newInstance()));
b.janani68c55e12016-02-24 12:23:03 +053066 }
67 }
68
69 /**
70 * This test case checks the received copyright header contents.
Bharat saraswal6ef0b762016-04-05 12:45:45 +053071 *
72 * @throws IOException when fails to do IO operations
b.janani68c55e12016-02-24 12:23:03 +053073 */
74 @Test
75 public void testGetCopyrightHeader() throws IOException {
76
Bharat saraswal6ef0b762016-04-05 12:45:45 +053077 String baseDir = System.getProperty("basedir");
78 String path = "/src/test/resources/CopyrightHeader.txt";
79
80 String licenseHeader = getCopyrightHeader();
b.janani68c55e12016-02-24 12:23:03 +053081 File test = new File("target/TestCopyrightHeader.txt");
82
83 FileWriter out = new FileWriter(test);
84 out.write(licenseHeader);
85 out.close();
86
Bharat saraswal6ef0b762016-04-05 12:45:45 +053087 assertThat(true, is(contentEquals(test, new File(baseDir + path))));
b.janani68c55e12016-02-24 12:23:03 +053088 }
89}