11package root .repository .implement ;
22
33import static org .junit .jupiter .api .Assertions .assertEquals ;
4- import static org .junit .jupiter .api .Assertions .assertNotNull ;
5- import static org .junit .jupiter .api .Assertions .assertNull ;
6- import static org .junit .jupiter .api .Assertions .assertTrue ;
74import static org .junit .jupiter .api .Assertions .fail ;
8- import static org .mockito .Mockito .mock ;
9- import static org .mockito .Mockito .when ;
105
116import java .io .ByteArrayInputStream ;
127import java .io .IOException ;
138import java .io .InputStream ;
149import java .nio .file .Files ;
1510import java .nio .file .Paths ;
16- import java .util .List ;
1711
1812import org .junit .jupiter .api .AfterAll ;
1913import org .junit .jupiter .api .BeforeAll ;
20- import org .junit .jupiter .api .BeforeEach ;
2114import org .junit .jupiter .api .Test ;
2215
2316import com .jcraft .jsch .Channel ;
2821import root .common .server .implement .JschConnectionInfo ;
2922import root .common .server .implement .JschServer ;
3023import root .common .server .implement .ServerOS ;
31- import root .core .domain .OSDiskUsage ;
3224import root .core .repository .constracts .ServerMonitoringRepository ;
3325
3426public class WindowServerMonitoringRepositoryTest {
@@ -49,9 +41,9 @@ public static void before() {
4941
5042 String serverName = "testServer" ;
5143 ServerOS serverOS = ServerOS .WINDOW ;
52- String host = "192.168.154.1 " ;
44+ String host = "172.30.1.41 " ;
5345 int port = 22 ;
54- String id = "dky " ;
46+ String id = "aserv " ;
5547 String password = "ehruddbs1!" ;
5648
5749 jschServer = new JschServer (new JschConnectionInfo (serverName , serverOS , host , port , id , password ));
@@ -65,7 +57,7 @@ public static void before() {
6557 channel .connect ();
6658 ChannelSftp channelSftp = (ChannelSftp ) channel ;
6759 InputStream is = new ByteArrayInputStream (alertLogString .getBytes ());
68- channelSftp .put (is , "C: \\ test.txt" );
60+ channelSftp .put (is , "/ test.txt" );
6961 channelSftp .disconnect ();
7062 channel .disconnect ();
7163 } catch (Exception e ) {
@@ -76,8 +68,9 @@ public static void before() {
7668 @ AfterAll
7769 public static void teardown () {
7870 try {
79- // jschServer.executeCommand("rd /s /q C:\\test.txt");
71+ jschServer .executeCommand ("del C:\\ test.txt" );
8072 } catch (Exception e ) {
73+ fail (e .getMessage ());
8174 }
8275 }
8376
@@ -93,7 +86,7 @@ public void testGetServerName() {
9386 @ Test
9487 public void testGetAlertLogFileLineCount () {
9588 // Arrange
96- AlertLogCommand alc = new AlertLogCommand (10 , "C:\\ test.txt" );
89+ AlertLogCommand alc = new AlertLogCommand (10 , "C:// test.txt" );
9790
9891 // Act
9992 int lineCount = repo .getAlertLogFileLineCount (alc );
@@ -105,7 +98,7 @@ public void testGetAlertLogFileLineCount() {
10598 @ Test
10699 public void testCheckAlertLog () throws Exception {
107100 // Arrange
108- AlertLogCommand alc = new AlertLogCommand (alertLogLines .length , "C:\\ test.txt" );
101+ AlertLogCommand alc = new AlertLogCommand (alertLogLines .length , "C:// test.txt" );
109102
110103 // Act
111104 String result = repo .checkAlertLog (alc );
@@ -117,15 +110,18 @@ public void testCheckAlertLog() throws Exception {
117110 @ Test
118111 public void testCheckAlertLog_Last10Lines () throws Exception {
119112 // Arrange
120- AlertLogCommand alc = new AlertLogCommand (10 , "C:\\ test.txt" );
113+ AlertLogCommand alc = new AlertLogCommand (10 , "C:// test.txt" );
121114
122115 // Act
123116 String result = repo .checkAlertLog (alc );
124117
125118 // Assert
126119 StringBuffer expected = new StringBuffer ();
127120 for (int i = alertLogLines .length - 10 ; i < alertLogLines .length ; i ++) {
128- expected .append (alertLogLines [i ]).append ("\n " );
121+ expected .append (alertLogLines [i ]);
122+ if (i != alertLogLines .length -1 ) {
123+ expected .append ("\n " );
124+ }
129125 }
130126 assertEquals (expected .toString (), result );
131127 }
@@ -139,117 +135,4 @@ public void testCheckOSDiskUsage() {
139135 // Assert
140136 // assertTrue(result.size() != 0);
141137 }
142-
143- /*
144- * @Test
145- * public void testGetServerName_ServerNameIsNull() {
146- * when(jschServer.getServerName()).thenReturn(null);
147- * String result = repo.getServerName();
148- * assertNull(result);
149- * }
150- *
151- * @Test
152- * public void testGetServerName_ServerNameIsNotNull() {
153- * when(jschServer.getServerName()).thenReturn("DKY SERVER");
154- * String result = repo.getServerName();
155- * assertNotNull(result);
156- * }
157- *
158- * @Test
159- * public void testGetAlertLogFileLineCount() throws Exception {
160- * // Arrange
161- * AlertLogCommand alc = new AlertLogCommand();
162- * alc.setReadFilePath("C:\\alert_DKYDB.log");
163- *
164- * String command = String.format("find /v /c \"\" %s", alc.getReadFilePath());
165- * when(jschServer.executeCommand(command)).thenReturn(String.valueOf(
166- * alertLogLines.length));
167- *
168- * // Act
169- * int lineCount = repo.getAlertLogFileLineCount(alc);
170- *
171- * // Assert
172- * assertEquals(lineCount, alertLogLines.length);
173- * }
174- *
175- * @Test
176- * public void testCheckAlertLog() throws Exception {
177- * // Arrange
178- * AlertLogCommand alc = new AlertLogCommand();
179- * alc.setReadLine(10);
180- * alc.setReadFilePath("C:\\alert_DKYDB.log");
181- *
182- * String command = String.format("tail %d %s", alc.getReadLine(),
183- * alc.getReadFilePath());
184- * when(jschServer.executeCommand(command)).thenReturn(alertLogString);
185- *
186- * // Act
187- * String result = repo.checkAlertLog(alc);
188- *
189- * // Assert
190- * assertEquals(result, alertLogString);
191- * }
192- */
193- /*
194- * @Test
195- * public void testCheckAlertLogDuringPeriod() throws Exception {
196- * // Arrange
197- * AlertLogCommand alc = new AlertLogCommand();
198- * alc.setReadLine(10);
199- * alc.setReadFilePath("C:\\alert_DKYDB.log");
200- *
201- * String command1 = String.format("find /v /c \"\" %s", alc.getReadFilePath());
202- * when(jschServer.executeCommand(command1)).thenReturn(String.valueOf(
203- * alertLogLines.length));
204- *
205- * String command2 = String.format("tail %d %s", alc.getReadLine(),
206- * alc.getReadFilePath());
207- * when(jschServer.executeCommand(command2)).thenReturn(alertLogString);
208- *
209- * // Act
210- * AlertLog alertLog = repo.checkAlertLogDuringPeriod(alc, "2022-03-24",
211- * "2022-03-29");
212- *
213- * // Assert
214- * assertEquals(alertLog.getTotalLineCount(), 12);
215- * assertEquals(alertLog.getAlertLogs().size(), 7);
216- * }
217- *
218- * @Test
219- * public void testCheckAlertLogDuringPeriod_ReadLineBiggerThenTotalLineCnt()
220- * throws Exception {
221- * // Arrange
222- * AlertLogCommand alc = new AlertLogCommand();
223- * alc.setReadLine(20);
224- * alc.setReadFilePath("C:\\alert_DKYDB.log");
225- *
226- * String command1 = String.format("find /v /c \"\" %s", alc.getReadFilePath());
227- * when(jschServer.executeCommand(command1)).thenReturn("26");
228- *
229- * String command2 = String.format("tail %d %s", alc.getReadLine(),
230- * alc.getReadFilePath());
231- * StringBuilder builder = new StringBuilder();
232- * for (int i = 0; i < Math.min(alertLogLines.length, alc.getReadLine()); i++) {
233- * builder.append(alertLogLines[i]).append("\n");
234- * }
235- * when(jschServer.executeCommand(command2)).thenReturn(builder.toString());
236- *
237- * String command3 = String.format("tail %d %s", alc.getReadLine() * 2,
238- * alc.getReadFilePath());
239- * builder = new StringBuilder();
240- * for (int i = 0; i < Math.min(alertLogLines.length, alc.getReadLine() * 2);
241- * i++) {
242- * builder.append(alertLogLines[i]).append("\n");
243- * }
244- * when(jschServer.executeCommand(command3)).thenReturn(builder.toString());
245- *
246- * // Act
247- * AlertLog alertLog = repo.checkAlertLogDuringPeriod(alc, "2022-03-23",
248- * "2022-03-24");
249- *
250- * // Assert
251- * assertEquals(alertLog.getTotalLineCount(), 3);
252- * assertEquals(alertLog.getAlertLogs().size(), 2);
253- * }
254- */
255138}
0 commit comments