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) 2008, 2021, Oracle and/or its affiliates. All rights reserved. 22 */ 23 package org.opengrok.indexer.history; 24 25 import org.junit.jupiter.api.AfterEach; 26 import org.junit.jupiter.api.BeforeEach; 27 import org.junit.jupiter.api.Test; 28 29 import static org.junit.jupiter.api.Assertions.assertEquals; 30 import static org.junit.jupiter.api.Assertions.assertNotNull; 31 import static org.junit.jupiter.api.Assertions.assertTrue; 32 33 /** 34 * 35 * @author austvik 36 */ 37 public class ClearCaseHistoryParserTest { 38 39 private ClearCaseHistoryParser instance; 40 41 @BeforeEach setUp()42 public void setUp() { 43 instance = new ClearCaseHistoryParser(); 44 } 45 46 @AfterEach tearDown()47 public void tearDown() { 48 instance = null; 49 } 50 51 /** 52 * Test of parse method, of class ClearCaseHistoryParser. 53 * @throws Exception exception 54 */ 55 @Test parseFileHistory()56 public void parseFileHistory() throws Exception { 57 String author1 = "First Last (username)"; 58 String author2 = "First2 Last2 (username2)"; 59 String output = "create version\n" + 60 "20020618.212343\n" + 61 author1 + "\n" + 62 "/main/3\n" + 63 "Merge from eeeee for ffffff\n" + 64 ".\n" + 65 "create version\n" + 66 "20020222.164239\n" + 67 author2 + "\n" + 68 "/main/2\n" + 69 "Merge from projper branch.\n" + 70 "Adding aaaaaaa to the yyyyy.\n" + 71 ".\n" + 72 "create version\n" + 73 "20020208.150825\n" + 74 author2 + "\n" + 75 "/main/1\n" + 76 "Target for javac set to 1.3.\n" + 77 "Fixed handling of " + 78 " res directory.\n" + 79 ".\n" + 80 "create version\n" + 81 "20010924.095104\n" + 82 author2 + "\n" + 83 "/main/0\n" + 84 "\n" + 85 ".\n" + 86 "create branch\n" + 87 "20010924.095104\n" + 88 author2 + "\n" + 89 "/main\n" + 90 "\n" + 91 ".\n" + 92 "create file element\n" + 93 "20010924.095104\n" + 94 author1 + "\n" + 95 "\n" + 96 "\n" + 97 "."; 98 99 History result = instance.parse(output); 100 assertNotNull(result); 101 assertEquals(4, result.getHistoryEntries().size()); 102 103 HistoryEntry e1 = result.getHistoryEntries().get(0); 104 assertEquals("/main/3", e1.getRevision()); 105 assertEquals(author1, e1.getAuthor()); 106 assertEquals(0, e1.getFiles().size()); 107 assertTrue(e1.getMessage().contains("eeeee")); 108 109 HistoryEntry e4 = result.getHistoryEntries().get(3); 110 assertEquals("/main/0", e4.getRevision()); 111 assertEquals(author2, e4.getAuthor()); 112 assertEquals(0, e4.getFiles().size()); 113 } 114 115 /** 116 * Test of parse method, of class ClearCaseHistoryParser. 117 * @throws Exception exception 118 */ 119 @Test parseDirHistory()120 public void parseDirHistory() throws Exception { 121 String author1 = "First Last (username)"; 122 String author2 = "First2 Last2 (username2)"; 123 String output = "create directory version\n" + 124 "20050401.162902\n" + 125 author1 + "\n" + 126 "/main/3\n" + 127 "Removed directory element \"prototype\".\n" + 128 ".\n" + 129 "create directory version\n" + 130 "20020618.215917\n" + 131 author2 + "\n" + 132 "/main/2\n" + 133 "Merge from wwwww for dddddd\n" + 134 ".\n" + 135 "create directory version\n" + 136 "20010228.174617\n" + 137 author1 + "\n" + 138 "/main/1\n" + 139 "New structure.\n" + 140 "\n" + 141 "Added directory element \"generic\".\n" + 142 "Added directory element \"prototype\".\n" + 143 "Added directory element \"install\".\n" + 144 "Added directory element \"service\".\n" + 145 ".\n" + 146 "create directory version\n" + 147 "20001215.092522\n" + 148 author2 + "\n" + 149 "/main/0\n" + 150 "\n" + 151 ".\n" + 152 "create branch\n" + 153 "20001215.092522\n" + 154 author1 + "\n" + 155 "/main\n" + 156 "\n" + 157 ".\n" + 158 "create directory element\n" + 159 "20001215.092522\n" + 160 author1 + "\n" + 161 "\n" + 162 "\n" + 163 "."; 164 History result = instance.parse(output); 165 assertNotNull(result); 166 assertEquals(4, result.getHistoryEntries().size()); 167 168 HistoryEntry e1 = result.getHistoryEntries().get(0); 169 assertEquals("/main/3", e1.getRevision()); 170 assertEquals(author1, e1.getAuthor()); 171 assertEquals(0, e1.getFiles().size()); 172 assertTrue(e1.getMessage().contains("prototype")); 173 174 HistoryEntry e4 = result.getHistoryEntries().get(3); 175 assertEquals("/main/0", e4.getRevision()); 176 assertEquals(author2, e4.getAuthor()); 177 assertEquals(0, e4.getFiles().size()); 178 } 179 180 } 181