blob: 3bd97976c0e25f80cd85265f5afdd13b3ec21e9e [file] [log] [blame]
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -08001/*
2 * Copyright 2015 Open Networking Laboratory
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.onosproject.ui;
17
18import com.google.common.collect.ImmutableList;
19import org.junit.Test;
20
21import java.io.IOException;
22
23import static com.google.common.io.ByteStreams.toByteArray;
Thomas Vachuska3553b302015-03-07 14:49:43 -080024import static org.junit.Assert.*;
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080025
26/**
27 * Tests the default user interface extension descriptor.
28 */
29public class UiExtensionTest {
30
31 @Test
32 public void basics() throws IOException {
33 UiExtension ext = new UiExtension(ImmutableList.of(new UiView("foo", "Foo View")),
Thomas Vachuska3553b302015-03-07 14:49:43 -080034 null,
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080035 getClass().getClassLoader());
36 String css = new String(toByteArray(ext.css()));
37 assertTrue("incorrect css stream", css.contains("foo-css"));
38 String js = new String(toByteArray(ext.js()));
39 assertTrue("incorrect js stream", js.contains("foo-js"));
40 assertEquals("incorrect views stream", "foo", ext.views().get(0).id());
Thomas Vachuska3553b302015-03-07 14:49:43 -080041 assertNull("incorrect handler factory", ext.messageHandlerFactory());
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080042 }
43
44 @Test
45 public void withPath() throws IOException {
46 UiExtension ext = new UiExtension(ImmutableList.of(new UiView("foo", "Foo View")),
Thomas Vachuska3553b302015-03-07 14:49:43 -080047 null, "custom", getClass().getClassLoader());
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080048 String css = new String(toByteArray(ext.css()));
49 assertTrue("incorrect css stream", css.contains("custom-css"));
50 String js = new String(toByteArray(ext.js()));
51 assertTrue("incorrect js stream", js.contains("custom-js"));
52 assertEquals("incorrect views stream", "foo", ext.views().get(0).id());
Thomas Vachuska3553b302015-03-07 14:49:43 -080053 assertNull("incorrect handler factory", ext.messageHandlerFactory());
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080054 }
55}