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 | 8b91f4f | 2015-04-23 17:55:36 -0700 | [diff] [blame] | 25 | import static org.onosproject.ui.UiView.Category.OTHER; |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 26 | |
| 27 | /** |
| 28 | * Tests the default user interface extension descriptor. |
| 29 | */ |
| 30 | public class UiExtensionTest { |
| 31 | |
| 32 | @Test |
| 33 | public void basics() throws IOException { |
Thomas Vachuska | 8b91f4f | 2015-04-23 17:55:36 -0700 | [diff] [blame] | 34 | UiExtension ext = new UiExtension(ImmutableList.of(new UiView(OTHER, "foo", "Foo View")), |
Thomas Vachuska | 3553b30 | 2015-03-07 14:49:43 -0800 | [diff] [blame] | 35 | null, |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 36 | 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 Vachuska | 8b91f4f | 2015-04-23 17:55:36 -0700 | [diff] [blame] | 41 | assertEquals("incorrect view id", "foo", ext.views().get(0).id()); |
| 42 | assertEquals("incorrect view category", OTHER, ext.views().get(0).category()); |
Thomas Vachuska | 3553b30 | 2015-03-07 14:49:43 -0800 | [diff] [blame] | 43 | assertNull("incorrect handler factory", ext.messageHandlerFactory()); |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | @Test |
| 47 | public void withPath() throws IOException { |
Thomas Vachuska | 8b91f4f | 2015-04-23 17:55:36 -0700 | [diff] [blame] | 48 | UiExtension ext = new UiExtension(ImmutableList.of(new UiView(OTHER, "foo", "Foo View")), |
Thomas Vachuska | 3553b30 | 2015-03-07 14:49:43 -0800 | [diff] [blame] | 49 | null, "custom", getClass().getClassLoader()); |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 50 | 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 Vachuska | 8b91f4f | 2015-04-23 17:55:36 -0700 | [diff] [blame] | 54 | assertEquals("incorrect view id", "foo", ext.views().get(0).id()); |
Thomas Vachuska | 3553b30 | 2015-03-07 14:49:43 -0800 | [diff] [blame] | 55 | assertNull("incorrect handler factory", ext.messageHandlerFactory()); |
Thomas Vachuska | fe8c98a | 2015-02-04 01:24:32 -0800 | [diff] [blame] | 56 | } |
| 57 | } |