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) 2013, 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 java.io.IOException; 30 31 import static org.junit.jupiter.api.Assertions.assertEquals; 32 import static org.junit.jupiter.api.Assertions.assertFalse; 33 import static org.junit.jupiter.api.Assertions.assertNotNull; 34 import static org.junit.jupiter.api.Assertions.assertTrue; 35 36 /** 37 * 38 * @author michailf 39 */ 40 public class SSCMHistoryParserTest { 41 42 SSCMHistoryParser instance; 43 44 @BeforeEach setUp()45 public void setUp() { 46 instance = new SSCMHistoryParser(new SSCMRepository()); 47 } 48 49 @AfterEach tearDown()50 public void tearDown() { 51 instance = null; 52 } 53 54 /** 55 * Test of parse method, of class GitHistoryParser. 56 * 57 * @throws java.io.IOException 58 */ 59 @Test parseEmpty()60 public void parseEmpty() throws IOException { 61 History result = instance.parse(""); 62 assertNotNull(result); 63 assertEquals(0, result.getHistoryEntries().size(), "Should not contain any history entries"); 64 } 65 66 /** 67 * Test of parsing output similar to that in Surround SCM own repository. 68 * 69 * @throws java.io.IOException 70 */ 71 @Test parseALaSSCM()72 public void parseALaSSCM() throws IOException { 73 // This is the new line that is generated by sscm (2011) history command 74 String newLine = "\r\r\n"; 75 76 String author1 = "Michailf"; 77 String author3 = "Joec"; 78 String author4 = "user4"; 79 String author5 = "user5"; 80 String date1 = "9/7/2013 1:10 PM"; 81 String date2 = "10/8/2013 1:13 PM"; 82 String date3 = "10/8/2013 1:14 PM"; 83 String date4 = "10/8/2013 1:15 PM"; 84 String date5 = "10/18/2013 11:16 PM"; 85 String comment3 = "Change with check in." + newLine 86 + "" + newLine 87 + "Third comment line"; 88 String comment5 = "Comment with promote"; 89 String output 90 = "Full file path: Branch1/Repo with spaces/readme.txt" + newLine 91 + "Branch: Branch1" + newLine 92 + "Working directory: C:\\scm\\Branch1\\Repo with spaces" + newLine 93 + "Action: User: Version: Date:" + newLine 94 + "add Michailf 1 " + date1 + newLine 95 + "add to branch[Bug#00000008 - Branch to work on changes.]" + newLine 96 + " Joec 1 " + date2 + newLine 97 + "checkin Joec 2 " + date3 + newLine 98 + " Comments - " + comment3 + newLine 99 + "promote from[Bug#00000008 - Branch to work on changes. v. 2]" + newLine 100 + " user4 3 " + date4 + newLine 101 + "promote from[Bug#00000008 - Branch to work on changes. v. 3]" + newLine 102 + " user5 4 " + date5 + newLine 103 + " Comments - " + comment5 + newLine; 104 105 History result = instance.parse(output); 106 assertNotNull(result); 107 // History entries that do not increment version number are not included 108 // (no file changes) 109 assertEquals(4, result.getHistoryEntries().size(), "Should contain four history entries"); 110 // History entries are reversed (newest first) 111 { 112 HistoryEntry e0 = result.getHistoryEntries().get(0); 113 assertEquals("4", e0.getRevision()); 114 assertEquals(author5, e0.getAuthor()); 115 assertFalse(e0.getMessage().isEmpty()); 116 assertEquals(0, e0.getFiles().size()); 117 } 118 119 { 120 HistoryEntry e1 = result.getHistoryEntries().get(1); 121 assertEquals("3", e1.getRevision()); 122 assertEquals(author4, e1.getAuthor()); 123 assertFalse(e1.getMessage().isEmpty()); 124 assertEquals(0, e1.getFiles().size()); 125 } 126 127 { 128 HistoryEntry e2 = result.getHistoryEntries().get(2); 129 assertEquals("2", e2.getRevision()); 130 assertEquals(author3, e2.getAuthor()); 131 assertFalse(e2.getMessage().isEmpty()); 132 assertEquals(0, e2.getFiles().size()); 133 } 134 135 { 136 HistoryEntry e3 = result.getHistoryEntries().get(3); 137 assertEquals("1", e3.getRevision()); 138 assertEquals(author1, e3.getAuthor()); 139 assertTrue(e3.getMessage().isEmpty()); 140 assertEquals(0, e3.getFiles().size()); 141 } 142 } 143 } 144