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
|
/*******************************************************************************
* Copyright (c) 2004, 2007 Boeing.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Boeing - initial API and implementation
*******************************************************************************/
package org.eclipse.osee.framework.skynet.core.artifact;
import static org.eclipse.osee.framework.core.enums.DeletionFlag.EXCLUDE_DELETED;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.Collection;
import org.eclipse.osee.framework.core.enums.CoreAttributeTypes;
import org.eclipse.osee.framework.jdk.core.util.GUID;
import org.eclipse.osee.framework.jdk.core.util.Lib;
import org.eclipse.osee.framework.plugin.core.util.OseeData;
import org.eclipse.osee.framework.skynet.core.artifact.search.ArtifactQuery;
import org.eclipse.osee.framework.skynet.core.utility.CsvArtifact;
import org.eclipse.osee.support.test.util.DemoSawBuilds;
/**
* @author Ryan D. Brooks
*/
public class NativeArtifactTest {
@org.junit.Test
public void testCleanupPre() throws Exception {
cleanup();
}
@org.junit.Test
public void testNativeArtifact() throws Exception {
CsvArtifact csvArtifact = CsvArtifact.getCsvArtifact(getClass().getSimpleName(), DemoSawBuilds.SAW_Bld_1, true);
assertNotNull(csvArtifact);
Artifact artifact = csvArtifact.getArtifact();
assertTrue(artifact.isAttributeTypeValid(CoreAttributeTypes.NativeContent));
assertTrue(artifact.isAttributeTypeValid(CoreAttributeTypes.Extension));
}
@org.junit.Test
public void testGetFileExtension() throws Exception {
Artifact nativeArtifact = getNativeArtifact();
assertTrue(nativeArtifact.getSoleAttributeValue(CoreAttributeTypes.Extension, "").equals("csv"));
}
@org.junit.Test
public void testSetAndGetValueAsString() throws Exception {
Artifact nativeArtifact = getNativeArtifact();
nativeArtifact.setSoleAttributeFromString(CoreAttributeTypes.NativeContent, "hello world");
nativeArtifact.persist();
String content = nativeArtifact.getSoleAttributeValueAsString(CoreAttributeTypes.NativeContent, "");
assertEquals("hello world", content);
}
@org.junit.Test
public void testSetAndGetNativeContent() throws Exception {
File file = OseeData.getFile(GUID.create() + ".txt");
Lib.writeStringToFile("hello world", file);
Artifact nativeArtifact = getNativeArtifact();
nativeArtifact.setSoleAttributeFromStream(CoreAttributeTypes.NativeContent, new FileInputStream(file));
nativeArtifact.persist();
InputStream inputStream = null;
try {
inputStream = nativeArtifact.getSoleAttributeValue(CoreAttributeTypes.NativeContent, null);
String content = Lib.inputStreamToString(inputStream);
assertEquals("hello world", content);
} finally {
Lib.close(inputStream);
}
}
@org.junit.Test
public void testCleanupPost() throws Exception {
cleanup();
}
private Artifact getNativeArtifact() throws Exception {
return CsvArtifact.getCsvArtifact(getClass().getSimpleName(), DemoSawBuilds.SAW_Bld_1, false).getArtifact();
}
private void cleanup() throws Exception {
Collection<Artifact> arts =
ArtifactQuery.getArtifactListFromName(getClass().getSimpleName(), DemoSawBuilds.SAW_Bld_1, EXCLUDE_DELETED);
new PurgeArtifacts(arts).execute();
}
}
|