Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 16 | package org.onosproject.ui; |
| 17 | |
| 18 | import com.google.common.collect.ImmutableList; |
| 19 | import org.junit.Test; |
| 20 | |
| 21 | import java.io.IOException; |
| 22 | |
| 23 | import static com.google.common.io.ByteStreams.toByteArray; |
Thomas Vachuska | 3553b30 | 2015-03-07 14:49:43 -0800 | [diff] [blame] | 24 | import static org.junit.Assert.*; |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 25 | |
| 26 | /** |
| 27 | * Tests the default user interface extension descriptor. |
| 28 | */ |
| 29 | public class UiExtensionTest { |
| 30 | |
| 31 | @Test |
| 32 | public void basics() throws IOException { |
| 33 | UiExtension ext = new UiExtension(ImmutableList.of(new UiView("foo", "Foo View")), |
Thomas Vachuska | 3553b30 | 2015-03-07 14:49:43 -0800 | [diff] [blame] | 34 | null, |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 35 | 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 Vachuska | 3553b30 | 2015-03-07 14:49:43 -0800 | [diff] [blame] | 41 | assertNull("incorrect handler factory", ext.messageHandlerFactory()); |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | @Test |
| 45 | public void withPath() throws IOException { |
| 46 | UiExtension ext = new UiExtension(ImmutableList.of(new UiView("foo", "Foo View")), |
Thomas Vachuska | 3553b30 | 2015-03-07 14:49:43 -0800 | [diff] [blame] | 47 | null, "custom", getClass().getClassLoader()); |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 48 | 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 Vachuska | 3553b30 | 2015-03-07 14:49:43 -0800 | [diff] [blame] | 53 | assertNull("incorrect handler factory", ext.messageHandlerFactory()); |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 54 | } |
| 55 | } |