1 /*******************************************************************************
2 * Copyright (c) 2015 Ericsson
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * Marc-Andre Laperle - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.tracecompass
.tmf
.remote
.ui
.tests
.fetch
;
15 import static org
.junit
.Assert
.assertEquals
;
17 import java
.io
.ByteArrayInputStream
;
19 import java
.nio
.file
.Files
;
20 import java
.nio
.file
.Paths
;
22 import org
.eclipse
.tracecompass
.internal
.tmf
.remote
.ui
.wizards
.fetch
.model
.RemoteImportConnectionNodeElement
;
23 import org
.eclipse
.tracecompass
.internal
.tmf
.remote
.ui
.wizards
.fetch
.model
.RemoteImportProfileElement
;
24 import org
.eclipse
.tracecompass
.internal
.tmf
.remote
.ui
.wizards
.fetch
.model
.RemoteImportProfilesReader
;
25 import org
.eclipse
.tracecompass
.internal
.tmf
.remote
.ui
.wizards
.fetch
.model
.RemoteImportProfilesWriter
;
26 import org
.eclipse
.tracecompass
.internal
.tmf
.remote
.ui
.wizards
.fetch
.model
.RemoteImportTraceGroupElement
;
27 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.project
.wizards
.tracepkg
.TracePackageElement
;
28 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.project
.wizards
.tracepkg
.TracePackageFilesElement
;
29 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.project
.wizards
.tracepkg
.TracePackageTraceElement
;
30 import org
.junit
.Test
;
33 * Test writing profiles from XML
35 public class RemoteImportProfilesWriterTest
extends
36 AbstractRemoteImportProfilesIOTest
{
38 private static final String ENCODING
= "UTF-8"; //$NON-NLS-1$
41 * Test writing a profiles file.
47 public void testValidateValid() throws Exception
{
48 String writtenXML
= RemoteImportProfilesWriter
.writeProfilesToXML(generateElements());
49 ByteArrayInputStream inputStream
= new ByteArrayInputStream(
50 writtenXML
.getBytes(ENCODING
));
51 RemoteImportProfilesReader
.validate(inputStream
);
53 File expectedFile
= getProfilesFile(VALID_PROFILE_PATH
);
54 String expectedContent
= new String(
55 Files
.readAllBytes(Paths
.get(expectedFile
.toURI())), ENCODING
);
56 assertEquals(expectedContent
, writtenXML
);
59 private static TracePackageElement
[] generateElements() {
60 RemoteImportProfileElement profileElement
= new RemoteImportProfileElement(
61 null, "myProfile"); //$NON-NLS-1$
62 RemoteImportConnectionNodeElement nodeElement
= new RemoteImportConnectionNodeElement(profileElement
,
63 "myhost", "ssh://user@127.0.0.1:22"); //$NON-NLS-1$//$NON-NLS-2$
64 RemoteImportTraceGroupElement traceGroupElement
= new RemoteImportTraceGroupElement(
65 nodeElement
, "/home/user/traces/test/test_with_lttng"); //$NON-NLS-1$
66 traceGroupElement
.setRecursive(true);
67 // Profile 1 > Node 1 > Group 1
68 TracePackageTraceElement traceElement
= new TracePackageTraceElement(
70 "test.log.(group1)", "org.eclipse.tracecompass.tmf.remote.ui.test.tracetype1"); //$NON-NLS-1$//$NON-NLS-2$
71 new TracePackageFilesElement(traceElement
, ".*test\\.log\\.(\\d+)"); //$NON-NLS-1$
72 traceElement
= new TracePackageTraceElement(
74 "TestLog.(group1)", "org.eclipse.tracecompass.tmf.remote.ui.test.tracetype2"); //$NON-NLS-1$//$NON-NLS-2$
75 new TracePackageFilesElement(traceElement
, ".*TestLog\\.(\\d+)"); //$NON-NLS-1$
77 // Profile 1 > Node 1 > Group 2
78 traceGroupElement
= new RemoteImportTraceGroupElement(nodeElement
,
79 "/home/user/traces/test/"); //$NON-NLS-1$
80 traceGroupElement
.setRecursive(false);
81 traceElement
= new TracePackageTraceElement(traceGroupElement
,
82 "lttng/(group1)", "org.eclipse.linuxtools.tmf.ui.type.ctf"); //$NON-NLS-1$//$NON-NLS-2$
83 new TracePackageFilesElement(traceElement
, "lttng/(.*)"); //$NON-NLS-1$
85 // Profile 1 > Node 2 > Group 1
86 nodeElement
= new RemoteImportConnectionNodeElement(profileElement
,"myhost3", "ssh://user@127.0.0.1:22"); //$NON-NLS-1$//$NON-NLS-2$
87 traceGroupElement
= new RemoteImportTraceGroupElement(nodeElement
, "/home"); //$NON-NLS-1$
88 traceGroupElement
.setRecursive(false);
89 traceElement
= new TracePackageTraceElement(traceGroupElement
, "", "trace.type"); //$NON-NLS-1$//$NON-NLS-2$
90 new TracePackageFilesElement(traceElement
, ".*"); //$NON-NLS-1$
92 // Profile 2 > Node 1 > Group 1
93 RemoteImportProfileElement profileElement2
= new RemoteImportProfileElement(
94 null, "myProfile2"); //$NON-NLS-1$
95 RemoteImportConnectionNodeElement nodeElement2
= new RemoteImportConnectionNodeElement(profileElement2
,
96 "myhost2", "ssh://user@142.111.222.333:22"); //$NON-NLS-1$//$NON-NLS-2$
97 traceGroupElement
= new RemoteImportTraceGroupElement(nodeElement2
,
98 "/home/user/traces/test/"); //$NON-NLS-1$
99 traceGroupElement
.setRecursive(false);
100 traceElement
= new TracePackageTraceElement(traceGroupElement
,
101 "lttng/(group1)", "org.eclipse.linuxtools.tmf.ui.type.ctf"); //$NON-NLS-1$//$NON-NLS-2$
102 new TracePackageFilesElement(traceElement
, "lttng/(.*)"); //$NON-NLS-1$
104 return new TracePackageElement
[] { profileElement
, profileElement2
};