Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 2c0a5e4b423eb36a7647f61965c79dcd9647aa30 (plain) (blame)
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
124
125
126
127
128
129
130
131
132
133
134
135
136
/*******************************************************************************
 * Copyright (c) 2012 protos software gmbh (http://www.protos.de).
 * 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:
 * 		Henrik Rentz-Reichert (initial contribution)
 * 
 *******************************************************************************/

package org.eclipse.etrice.etunit.converter;

import static org.junit.Assert.assertEquals;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;

import org.eclipse.core.runtime.FileLocator;
import org.eclipse.etrice.etunit.converter.EtUnitReportConverter.BaseOptions;
import org.eclipse.etrice.etunit.converter.tests.Activator;
import org.junit.Before;
import org.junit.Test;

import com.google.common.base.Charsets;
import com.google.common.io.Files;

/**
 * @author Henrik Rentz-Reichert
 *
 */
public class ConverterTest {

	private String basePath;
	private String expectsPath;

	@Before
	public void prepare() {
		try {
			URL modelsDir = Activator.getInstance().getBundle().getEntry("reports");
			URL fileURL = FileLocator.toFileURL(modelsDir);
			basePath = fileURL.getFile();
		} catch (IOException e) {
			e.printStackTrace();
		}
		try {
			URL modelsDir = Activator.getInstance().getBundle().getEntry("expects");
			URL fileURL = FileLocator.toFileURL(modelsDir);
			expectsPath = fileURL.getFile();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	@Test
	public void testConversion() throws IOException {
		ArrayList<String> args = new ArrayList<String>();
		args.add(basePath+"report1.etu");
		
		String[] arguments = new String[args.size()];
		new EtUnitReportConverter().run(args.toArray(arguments));
		
		assertEquals(Files.toString(new File(expectsPath+"report1.xml"), Charsets.UTF_8), Files.toString(new File(basePath+"report1.xml"), Charsets.UTF_8));
	}
	

	@Test
	public void testDoubleConversion() {
		ArrayList<String> args = new ArrayList<String>();
		args.add(basePath+"report1.etu");
		args.add(basePath+"report2.etu");
		
		String[] arguments = new String[args.size()];
		new EtUnitReportConverter().run(args.toArray(arguments));
	}

	@Test
	public void testCombine() {
		ArrayList<String> args = new ArrayList<String>();
		args.add(basePath+"report1.etu");
		args.add(basePath+"report2.etu");
		args.add(EtUnitReportConverter.OPTION_COMBINED);
		args.add(basePath+"combined.xml");
		
		String[] arguments = new String[args.size()];
		new EtUnitReportConverter().run(args.toArray(arguments));
	}

	@Test
	public void testOnlyCombine() {
		ArrayList<String> args = new ArrayList<String>();
		args.add(basePath+"report3.etu");
		args.add(basePath+"report4.etu");
		args.add(EtUnitReportConverter.OPTION_ONLY_COMBINED);
		args.add(basePath+"only_combined.xml");
		
		String[] arguments = new String[args.size()];
		new EtUnitReportConverter().run(args.toArray(arguments));
	}

	@Test
	public void testChangeSuiteName() {
		ArrayList<String> args = new ArrayList<String>();
		args.add(basePath+"report5.etu");
		args.add(EtUnitReportConverter.OPTION_SUITE_NAME);
		args.add("new.suite.name");
		
		String[] arguments = new String[args.size()];
		new EtUnitReportConverter().run(args.toArray(arguments));
	}

	@Test
	public void testEmptyFile() {
		ArrayList<String> args = new ArrayList<String>();
		args.add(basePath+"report6.etu");
		
		String[] arguments = new String[args.size()];
		new EtUnitReportConverter().run(args.toArray(arguments));
	}
	
	@Test
	public void testInMemory() throws IOException {
		List<InputStream> streams = new ArrayList<InputStream>();
		streams.add(new FileInputStream(new File(basePath+"report1.etu")));
		
		List<String> results = new EtUnitReportConverter().convert(new BaseOptions(), streams);
		assertEquals(1,  results.size());
		assertEquals(Files.toString(new File(expectsPath+"report1.xml"), Charsets.UTF_8), results.get(0));
	}
}

Back to the top