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$
39 private static final String LINE_SEPARATOR_PROPERTY
= "line.separator";
42 * Test writing a profiles file.
48 public void testValidateValid() throws Exception
{
49 String writtenXML
= RemoteImportProfilesWriter
.writeProfilesToXML(generateElements());
50 ByteArrayInputStream inputStream
= new ByteArrayInputStream(
51 writtenXML
.getBytes(ENCODING
));
52 RemoteImportProfilesReader
.validate(inputStream
);
54 File expectedFile
= getProfilesFile(VALID_PROFILE_PATH
);
55 String expectedContent
= new String(
56 Files
.readAllBytes(Paths
.get(expectedFile
.toURI())), ENCODING
);
58 // On windows, \r\n will be written to the XML. Replace them with \n for
60 String sysLineSeparator
= System
.getProperty(LINE_SEPARATOR_PROPERTY
);
61 writtenXML
= writtenXML
.replace(sysLineSeparator
, "\n");
63 assertEquals(expectedContent
, writtenXML
);
66 private static TracePackageElement
[] generateElements() {
67 RemoteImportProfileElement profileElement
= new RemoteImportProfileElement(
68 null, "myProfile"); //$NON-NLS-1$
69 RemoteImportConnectionNodeElement nodeElement
= new RemoteImportConnectionNodeElement(profileElement
,
70 "myhost", "ssh://user@127.0.0.1:22"); //$NON-NLS-1$//$NON-NLS-2$
71 RemoteImportTraceGroupElement traceGroupElement
= new RemoteImportTraceGroupElement(
72 nodeElement
, "/home/user/traces/test/test_with_lttng"); //$NON-NLS-1$
73 traceGroupElement
.setRecursive(true);
74 // Profile 1 > Node 1 > Group 1
75 TracePackageTraceElement traceElement
= new TracePackageTraceElement(
77 "test.log.(group1)", "org.eclipse.tracecompass.tmf.remote.ui.test.tracetype1"); //$NON-NLS-1$//$NON-NLS-2$
78 new TracePackageFilesElement(traceElement
, ".*test\\.log\\.(\\d+)"); //$NON-NLS-1$
79 traceElement
= new TracePackageTraceElement(
81 "TestLog.(group1)", "org.eclipse.tracecompass.tmf.remote.ui.test.tracetype2"); //$NON-NLS-1$//$NON-NLS-2$
82 new TracePackageFilesElement(traceElement
, ".*TestLog\\.(\\d+)"); //$NON-NLS-1$
84 // Profile 1 > Node 1 > Group 2
85 traceGroupElement
= new RemoteImportTraceGroupElement(nodeElement
,
86 "/home/user/traces/test/"); //$NON-NLS-1$
87 traceGroupElement
.setRecursive(false);
88 traceElement
= new TracePackageTraceElement(traceGroupElement
,
89 "lttng/(group1)", "org.eclipse.linuxtools.tmf.ui.type.ctf"); //$NON-NLS-1$//$NON-NLS-2$
90 new TracePackageFilesElement(traceElement
, "lttng/(.*)"); //$NON-NLS-1$
92 // Profile 1 > Node 2 > Group 1
93 nodeElement
= new RemoteImportConnectionNodeElement(profileElement
,"myhost3", "ssh://user@127.0.0.1:22"); //$NON-NLS-1$//$NON-NLS-2$
94 traceGroupElement
= new RemoteImportTraceGroupElement(nodeElement
, "/home"); //$NON-NLS-1$
95 traceGroupElement
.setRecursive(false);
96 traceElement
= new TracePackageTraceElement(traceGroupElement
, "", "trace.type"); //$NON-NLS-1$//$NON-NLS-2$
97 new TracePackageFilesElement(traceElement
, ".*"); //$NON-NLS-1$
99 // Profile 2 > Node 1 > Group 1
100 RemoteImportProfileElement profileElement2
= new RemoteImportProfileElement(
101 null, "myProfile2"); //$NON-NLS-1$
102 RemoteImportConnectionNodeElement nodeElement2
= new RemoteImportConnectionNodeElement(profileElement2
,
103 "myhost2", "ssh://user@142.111.222.333:22"); //$NON-NLS-1$//$NON-NLS-2$
104 traceGroupElement
= new RemoteImportTraceGroupElement(nodeElement2
,
105 "/home/user/traces/test/"); //$NON-NLS-1$
106 traceGroupElement
.setRecursive(false);
107 traceElement
= new TracePackageTraceElement(traceGroupElement
,
108 "lttng/(group1)", "org.eclipse.linuxtools.tmf.ui.type.ctf"); //$NON-NLS-1$//$NON-NLS-2$
109 new TracePackageFilesElement(traceElement
, "lttng/(.*)"); //$NON-NLS-1$
111 return new TracePackageElement
[] { profileElement
, profileElement2
};