analysis.lami: Add tests for the LAMI JSON protocol parsing
[deliverable/tracecompass.git] / analysis / org.eclipse.tracecompass.analysis.lami.core.tests / src / org / eclipse / tracecompass / analysis / lami / core / tests / LamiAnalysisStub.java
1 /*******************************************************************************
2 * Copyright (c) 2016 EfficiOS Inc., Michael Jeanson
3 *
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
8 *******************************************************************************/
9
10 package org.eclipse.tracecompass.analysis.lami.core.tests;
11
12 import static org.junit.Assert.fail;
13
14 import java.io.BufferedReader;
15 import java.io.IOException;
16 import java.io.InputStream;
17 import java.io.InputStreamReader;
18 import java.net.URL;
19 import java.util.Collections;
20 import java.util.List;
21 import java.util.stream.Collectors;
22
23 import org.eclipse.core.runtime.IProgressMonitor;
24 import org.eclipse.jdt.annotation.NonNull;
25 import org.eclipse.jdt.annotation.Nullable;
26 import org.eclipse.tracecompass.internal.provisional.analysis.lami.core.module.LamiAnalysis;
27 import org.eclipse.tracecompass.internal.provisional.analysis.lami.core.module.LamiChartModel;
28 import org.eclipse.tracecompass.tmf.core.analysis.ondemand.OnDemandAnalysisException;
29 import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
30
31 import com.google.common.collect.ImmutableMultimap;
32 import com.google.common.collect.Multimap;
33
34 /**
35 * Extension of {@link LamiAnalysis} used for tests.
36 */
37 public class LamiAnalysisStub extends LamiAnalysis {
38
39 private final String fMetaDatafilename;
40 private final String fResultFilename;
41
42 /**
43 * Constructor.
44 *
45 * @param metaDatafilename
46 * Filename of the JSON metadata file.
47 * @param resultFilename
48 * Filename of the JSON results file.
49 */
50 protected LamiAnalysisStub(String metaDatafilename, String resultFilename) {
51 super("Stub Analysis", false, o -> true, Collections.singletonList("StubExecutable"));
52 fMetaDatafilename = metaDatafilename;
53 fResultFilename = resultFilename;
54 }
55
56 @Override
57 public @NonNull String getName() {
58 return "StubName";
59 }
60
61 @Override
62 protected @NonNull Multimap<@NonNull String, @NonNull LamiChartModel> getPredefinedCharts() {
63 return ImmutableMultimap.of();
64 }
65
66 @Override
67 protected String getResultsFromCommand(List<String> command, IProgressMonitor monitor)
68 throws OnDemandAnalysisException {
69
70 return readLamiFile(fResultFilename);
71 }
72
73 @Override
74 protected @Nullable String getOutputFromCommand(List<String> command) {
75 return readLamiFile(fMetaDatafilename);
76 }
77
78 @Override
79 public boolean canExecute(ITmfTrace trace) {
80 initialize();
81 return true;
82 }
83
84 @Override
85 protected synchronized void initialize() {
86 checkMetadata();
87 }
88
89 private static String readLamiFile(String filename) {
90 String fileContent = "";
91 try {
92 URL url = new URL("platform:/plugin/org.eclipse.tracecompass.analysis.lami.core.tests/testfiles/" + filename);
93
94 try (InputStream inputStream = url.openConnection().getInputStream()) {
95 BufferedReader in = new BufferedReader(new InputStreamReader(inputStream));
96 fileContent = in.lines().collect(Collectors.joining());
97 }
98 } catch (IOException e) {
99 fail(e.getMessage());
100 }
101
102 return fileContent;
103 }
104 }
This page took 0.033844 seconds and 5 git commands to generate.