xref: /OpenGrok/opengrok-indexer/src/test/java/org/opengrok/indexer/index/IndexAnalysisSettingsTest.java (revision d6df19e1b22784c78f567cf74c42f18e3901b900)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * See LICENSE.txt included in this distribution for the specific
9  * language governing permissions and limitations under the License.
10  *
11  * When distributing Covered Code, include this CDDL HEADER in each
12  * file and include the License file at LICENSE.txt.
13  * If applicable, add the following below this CDDL HEADER, with the
14  * fields enclosed by brackets "[]" replaced with your own identifying
15  * information: Portions Copyright [yyyy] [name of copyright owner]
16  *
17  * CDDL HEADER END
18  */
19 
20 /*
21  * Copyright (c) 2018, Chris Fraire <cfraire@me.com>.
22  */
23 package org.opengrok.indexer.index;
24 
25 import java.io.IOException;
26 
27 import org.junit.jupiter.api.Test;
28 import org.opengrok.indexer.search.QueryBuilder;
29 
30 import static org.junit.jupiter.api.Assertions.assertEquals;
31 import static org.junit.jupiter.api.Assertions.assertNotNull;
32 import static org.junit.jupiter.api.Assertions.assertNull;
33 
34 /**
35  * Represents a test class for {@link IndexAnalysisSettings}.
36  */
37 public class IndexAnalysisSettingsTest {
38 
39     private static final String PROJECT_NAME = "foo-1-2-3";
40     private static final long ANALYZER_GURU_VERSION = 3;
41     private static final int TABSIZE = 17;
42 
43     @Test
shouldAffirmIndexAnalysisSettingsObjuid()44     public void shouldAffirmIndexAnalysisSettingsObjuid() {
45         String objuid = QueryBuilder.normalizeDirPath("58859C75-F941-42E5-8D1A-FAF71DDEBBA7");
46         assertEquals(objuid, IndexAnalysisSettingsAccessor.INDEX_ANALYSIS_SETTINGS_OBJUID,
47                 "IndexAnalysisSettingsDao objuid");
48     }
49 
50     @Test
shouldRoundTripANullObject()51     public void shouldRoundTripANullObject() throws IOException, ClassNotFoundException {
52         IndexAnalysisSettings obj = new IndexAnalysisSettings();
53         byte[] bin = obj.serialize();
54 
55         IndexAnalysisSettings res = IndexAnalysisSettings.deserialize(bin);
56         assertNotNull(res);
57         assertNull(res.getProjectName(), "projectName");
58         assertNull(res.getTabSize(), "tabSize");
59         assertNull(res.getAnalyzerGuruVersion(), "analyzerGuruVersion");
60     }
61 
62     @Test
shouldRoundTripADefinedObject()63     public void shouldRoundTripADefinedObject() throws IOException,
64             ClassNotFoundException {
65         IndexAnalysisSettings obj = new IndexAnalysisSettings();
66         obj.setProjectName(PROJECT_NAME);
67         obj.setAnalyzerGuruVersion(ANALYZER_GURU_VERSION);
68         obj.setTabSize(TABSIZE);
69         byte[] bin = obj.serialize();
70 
71         IndexAnalysisSettings res = IndexAnalysisSettings.deserialize(bin);
72         assertNotNull(res);
73         assertEquals(PROJECT_NAME, res.getProjectName(), "projectName");
74         assertEquals(TABSIZE, (int) res.getTabSize(), "tabSize");
75         assertEquals(ANALYZER_GURU_VERSION, (long) res.getAnalyzerGuruVersion(), "analyzerGuruVersion");
76     }
77 }
78