blob: 35894f9cded59b4444a0bf0ddd652a7f84f10ce4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2018-2019 Nordix Foundation. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ============LICENSE_END=========================================================
*/
package org.onap.dcaegen2.collectors.datafile.model;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test;
import org.onap.dcaegen2.collectors.datafile.ftp.FileServerData;
import org.onap.dcaegen2.collectors.datafile.ftp.ImmutableFileServerData;
import org.onap.dcaegen2.collectors.datafile.ftp.Scheme;
public class FileDataTest {
private static final String FTPES_SCHEME = "ftpes://";
private static final String PM_FILE_NAME = "A20161224.1030-1045.bin.gz";
private static final String REMOTE_FILE_LOCATION = "/ftp/rop/" + PM_FILE_NAME;
private static final String USER = "usr";
private static final String PWD = "pwd";
private static final String SERVER_ADDRESS = "192.168.0.101";
private static final int PORT_22 = 22;
private static final String LOCATION_WITH_USER =
FTPES_SCHEME + USER + ":" + PWD + "@" + SERVER_ADDRESS + ":" + PORT_22 + REMOTE_FILE_LOCATION;
private static final String LOCATION_WITHOUT_USER =
FTPES_SCHEME + SERVER_ADDRESS + ":" + PORT_22 + REMOTE_FILE_LOCATION;
private MessageMetaData messageMetaData() {
return ImmutableMessageMetaData.builder() //
.productName("PRODUCT_NAME") //
.vendorName("VENDOR_NAME") //
.lastEpochMicrosec("LAST_EPOCH_MICROSEC") //
.sourceName("SOURCE_NAME") //
.startEpochMicrosec("START_EPOCH_MICROSEC") //
.timeZoneOffset("TIME_ZONE_OFFSET") //
.changeIdentifier("PM_MEAS_CHANGE_IDENTIFIER") //
.changeType("FILE_READY_CHANGE_TYPE") //
.build();
}
private FileData properFileDataWithUser() {
return ImmutableFileData.builder() //
.name("name") //
.location(LOCATION_WITH_USER) //
.compression("comp") //
.fileFormatType("type") //
.fileFormatVersion("version") //
.scheme(Scheme.FTPS) //
.messageMetaData(messageMetaData()) //
.build();
}
private FileData properFileDataWithoutUser() {
return ImmutableFileData.builder() //
.name("name") //
.location(LOCATION_WITHOUT_USER) //
.compression("comp") //
.fileFormatType("type") //
.fileFormatVersion("version") //
.scheme(Scheme.FTPS) //
.messageMetaData(messageMetaData()) //
.build();
}
@Test
public void fileServerData_properLocationWithUser() {
ImmutableFileServerData expectedFileServerData = ImmutableFileServerData.builder() //
.serverAddress(SERVER_ADDRESS) //
.port(PORT_22) //
.userId(USER) //
.password(PWD) //
.build();
FileServerData actualFileServerData = properFileDataWithUser().fileServerData();
assertEquals(expectedFileServerData, actualFileServerData);
}
@Test
public void fileServerData_properLocationWithoutUser() {
ImmutableFileServerData expectedFileServerData = ImmutableFileServerData.builder() //
.serverAddress(SERVER_ADDRESS) //
.port(PORT_22) //
.userId("") //
.password("") //
.build();
FileServerData actualFileServerData = properFileDataWithoutUser().fileServerData();
assertEquals(expectedFileServerData, actualFileServerData);
assertTrue(expectedFileServerData.port().isPresent());
}
@Test
public void remoteLocation_properLocation() {
String actualRemoteFilePath = properFileDataWithUser().remoteFilePath();
assertEquals(REMOTE_FILE_LOCATION, actualRemoteFilePath);
}
@Test
public void fileServerData_properLocationWithoutPort() {
ImmutableFileServerData fileServerData = ImmutableFileServerData.builder() //
.serverAddress(SERVER_ADDRESS) //
.userId("") //
.password("") //
.build();
assertFalse(fileServerData.port().isPresent());
}
}
|