-
Notifications
You must be signed in to change notification settings - Fork 2.8k
/
HeliumVisualizationFactoryTest.java
198 lines (173 loc) · 5.83 KB
/
HeliumVisualizationFactoryTest.java
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.zeppelin.helium;
import com.github.eirslett.maven.plugins.frontend.lib.InstallationException;
import com.github.eirslett.maven.plugins.frontend.lib.TaskRunnerException;
import com.google.common.io.Resources;
import org.apache.commons.io.FileUtils;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.LinkedList;
import java.util.List;
import static org.junit.Assert.*;
public class HeliumVisualizationFactoryTest {
private File tmpDir;
private HeliumVisualizationFactory hvf;
@Before
public void setUp() throws InstallationException, TaskRunnerException {
tmpDir = new File(System.getProperty("java.io.tmpdir") + "/ZeppelinLTest_" + System.currentTimeMillis());
tmpDir.mkdirs();
// get module dir
URL res = Resources.getResource("helium/webpack.config.js");
String resDir = new File(res.getFile()).getParent();
File moduleDir = new File(resDir + "/../../../../zeppelin-web/src/app/");
hvf = new HeliumVisualizationFactory(tmpDir,
new File(moduleDir, "tabledata"),
new File(moduleDir, "visualization"));
}
@After
public void tearDown() throws IOException {
FileUtils.deleteDirectory(tmpDir);
}
@Test
public void testInstallNpm() throws InstallationException {
assertFalse(new File(tmpDir, "vis/node/npm").isFile());
assertFalse(new File(tmpDir, "vis/node/node").isFile());
hvf.installNodeAndNpm();
assertTrue(new File(tmpDir, "vis/node/npm").isFile());
assertTrue(new File(tmpDir, "vis/node/node").isFile());
}
@Test
public void downloadPackage() throws TaskRunnerException {
HeliumPackage pkg = new HeliumPackage(
HeliumPackage.Type.VISUALIZATION,
"lodash",
"lodash",
"lodash@3.9.3",
"",
null,
"license",
"icon"
);
hvf.install(pkg);
assertTrue(new File(tmpDir, "vis/node_modules/lodash").isDirectory());
}
@Test
public void bundlePackage() throws IOException, TaskRunnerException {
HeliumPackage pkg = new HeliumPackage(
HeliumPackage.Type.VISUALIZATION,
"zeppelin-bubblechart",
"zeppelin-bubblechart",
"zeppelin-bubblechart@0.0.3",
"",
null,
"license",
"icon"
);
List<HeliumPackage> pkgs = new LinkedList<>();
pkgs.add(pkg);
File bundle = hvf.bundle(pkgs);
assertTrue(bundle.isFile());
long lastModified = bundle.lastModified();
// bundle again and check if it served from cache
bundle = hvf.bundle(pkgs);
assertEquals(lastModified, bundle.lastModified());
}
@Test
public void bundleLocalPackage() throws IOException, TaskRunnerException {
URL res = Resources.getResource("helium/webpack.config.js");
String resDir = new File(res.getFile()).getParent();
String localPkg = resDir + "/../../../src/test/resources/helium/vis1";
HeliumPackage pkg = new HeliumPackage(
HeliumPackage.Type.VISUALIZATION,
"vis1",
"vis1",
localPkg,
"",
null,
"license",
"fa fa-coffee"
);
List<HeliumPackage> pkgs = new LinkedList<>();
pkgs.add(pkg);
File bundle = hvf.bundle(pkgs);
assertTrue(bundle.isFile());
}
@Test
public void bundleErrorPropagation() throws IOException, TaskRunnerException {
URL res = Resources.getResource("helium/webpack.config.js");
String resDir = new File(res.getFile()).getParent();
String localPkg = resDir + "/../../../src/test/resources/helium/vis2";
HeliumPackage pkg = new HeliumPackage(
HeliumPackage.Type.VISUALIZATION,
"vis2",
"vis2",
localPkg,
"",
null,
"license",
"fa fa-coffee"
);
List<HeliumPackage> pkgs = new LinkedList<>();
pkgs.add(pkg);
File bundle = null;
try {
bundle = hvf.bundle(pkgs);
// should throw exception
assertTrue(false);
} catch (IOException e) {
assertTrue(e.getMessage().contains("error in the package"));
}
assertNull(bundle);
}
@Test
public void switchVersion() throws IOException, TaskRunnerException {
URL res = Resources.getResource("helium/webpack.config.js");
String resDir = new File(res.getFile()).getParent();
HeliumPackage pkgV1 = new HeliumPackage(
HeliumPackage.Type.VISUALIZATION,
"zeppelin-bubblechart",
"zeppelin-bubblechart",
"zeppelin-bubblechart@0.0.3",
"",
null,
"license",
"icon"
);
HeliumPackage pkgV2 = new HeliumPackage(
HeliumPackage.Type.VISUALIZATION,
"zeppelin-bubblechart",
"zeppelin-bubblechart",
"zeppelin-bubblechart@0.0.1",
"",
null,
"license",
"icon"
);
List<HeliumPackage> pkgsV1 = new LinkedList<>();
pkgsV1.add(pkgV1);
List<HeliumPackage> pkgsV2 = new LinkedList<>();
pkgsV2.add(pkgV2);
File bundle1 = hvf.bundle(pkgsV1);
File bundle2 = hvf.bundle(pkgsV2);
assertNotSame(bundle1.lastModified(), bundle2.lastModified());
}
}