blob: efc0261028a7da93151d889ff886235caafb45df [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 Vachuska8b91f4f2015-04-23 17:55:36 -070025import static org.onosproject.ui.UiView.Category.OTHER;
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080026
27/**
28 * Tests the default user interface extension descriptor.
29 */
30public class UiExtensionTest {
31
32 @Test
33 public void basics() throws IOException {
Thomas Vachuska8b91f4f2015-04-23 17:55:36 -070034 UiExtension ext = new UiExtension(ImmutableList.of(new UiView(OTHER, "foo", "Foo View")),
Thomas Vachuska3553b302015-03-07 14:49:43 -080035 null,
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080036 getClass().getClassLoader());
37 String css = new String(toByteArray(ext.css()));
38 assertTrue("incorrect css stream", css.contains("foo-css"));
39 String js = new String(toByteArray(ext.js()));
40 assertTrue("incorrect js stream", js.contains("foo-js"));
Thomas Vachuska8b91f4f2015-04-23 17:55:36 -070041 assertEquals("incorrect view id", "foo", ext.views().get(0).id());
42 assertEquals("incorrect view category", OTHER, ext.views().get(0).category());
Thomas Vachuska3553b302015-03-07 14:49:43 -080043 assertNull("incorrect handler factory", ext.messageHandlerFactory());
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080044 }
45
46 @Test
47 public void withPath() throws IOException {
Thomas Vachuska8b91f4f2015-04-23 17:55:36 -070048 UiExtension ext = new UiExtension(ImmutableList.of(new UiView(OTHER, "foo", "Foo View")),
Thomas Vachuska3553b302015-03-07 14:49:43 -080049 null, "custom", getClass().getClassLoader());
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080050 String css = new String(toByteArray(ext.css()));
51 assertTrue("incorrect css stream", css.contains("custom-css"));
52 String js = new String(toByteArray(ext.js()));
53 assertTrue("incorrect js stream", js.contains("custom-js"));
Thomas Vachuska8b91f4f2015-04-23 17:55:36 -070054 assertEquals("incorrect view id", "foo", ext.views().get(0).id());
Thomas Vachuska3553b302015-03-07 14:49:43 -080055 assertNull("incorrect handler factory", ext.messageHandlerFactory());
Thomas Vachuskafe8c98a2015-02-04 01:24:32 -080056 }
57}