kmcpeake | 4fe18c8 | 2015-11-17 20:07:39 +0000 | [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.faultmanagement.web; |
| 17 | |
kmcpeake | 4fe18c8 | 2015-11-17 20:07:39 +0000 | [diff] [blame] | 18 | import org.junit.Before; |
kmcpeake | 4fe18c8 | 2015-11-17 20:07:39 +0000 | [diff] [blame] | 19 | import org.junit.Ignore; |
Jian Li | 9d61649 | 2016-03-09 10:52:49 -0800 | [diff] [blame] | 20 | import org.junit.Test; |
kmcpeake | 4fe18c8 | 2015-11-17 20:07:39 +0000 | [diff] [blame] | 21 | import org.onlab.osgi.ServiceDirectory; |
| 22 | import org.onlab.osgi.TestServiceDirectory; |
| 23 | import org.onlab.rest.BaseResource; |
| 24 | import org.onosproject.codec.CodecService; |
| 25 | import org.onosproject.codec.impl.CodecManager; |
Jian Li | 8ae9120 | 2016-03-24 14:36:16 -0700 | [diff] [blame] | 26 | import org.onosproject.rest.resources.ResourceTest; |
kmcpeake | 4fe18c8 | 2015-11-17 20:07:39 +0000 | [diff] [blame] | 27 | |
Jian Li | 9d61649 | 2016-03-09 10:52:49 -0800 | [diff] [blame] | 28 | import javax.ws.rs.client.WebTarget; |
| 29 | |
| 30 | import static org.hamcrest.MatcherAssert.assertThat; |
| 31 | import static org.hamcrest.Matchers.containsString; |
| 32 | import static org.hamcrest.Matchers.not; |
| 33 | |
kmcpeake | 4fe18c8 | 2015-11-17 20:07:39 +0000 | [diff] [blame] | 34 | /** |
| 35 | * Test of the Fault Management Web REST API for Alarms. |
| 36 | */ |
| 37 | public class AlarmsWebResourceTest extends ResourceTest { |
| 38 | |
Jian Li | 9d61649 | 2016-03-09 10:52:49 -0800 | [diff] [blame] | 39 | |
| 40 | |
kmcpeake | 4fe18c8 | 2015-11-17 20:07:39 +0000 | [diff] [blame] | 41 | @Before |
Jian Li | 9d61649 | 2016-03-09 10:52:49 -0800 | [diff] [blame] | 42 | public void setUpMock() { |
kmcpeake | 4fe18c8 | 2015-11-17 20:07:39 +0000 | [diff] [blame] | 43 | |
kmcpeake | b172d5f | 2015-12-10 11:30:43 +0000 | [diff] [blame] | 44 | CodecManager codecService = new CodecManager(); |
kmcpeake | 4fe18c8 | 2015-11-17 20:07:39 +0000 | [diff] [blame] | 45 | codecService.activate(); |
| 46 | |
kmcpeake | b172d5f | 2015-12-10 11:30:43 +0000 | [diff] [blame] | 47 | ServiceDirectory testDirectory = new TestServiceDirectory() |
kmcpeake | 4fe18c8 | 2015-11-17 20:07:39 +0000 | [diff] [blame] | 48 | // Currently no alarms-service implemented |
| 49 | // .add(AlarmsService.class, alarmsService) |
| 50 | .add(CodecService.class, codecService); |
| 51 | BaseResource.setServiceDirectory(testDirectory); |
| 52 | } |
| 53 | |
| 54 | @Test |
| 55 | @Ignore |
| 56 | public void getAllAlarms() { |
Jian Li | 9d61649 | 2016-03-09 10:52:49 -0800 | [diff] [blame] | 57 | WebTarget wt = target(); |
| 58 | String response = wt.path("/alarms").request().get(String.class); |
kmcpeake | 4fe18c8 | 2015-11-17 20:07:39 +0000 | [diff] [blame] | 59 | // Ensure hard-coded alarms returned okay |
| 60 | assertThat(response, containsString("\"NE is not reachable\",")); |
| 61 | assertThat(response, containsString("\"Equipment Missing\",")); |
| 62 | } |
| 63 | |
| 64 | @Test |
| 65 | @Ignore |
| 66 | public void getAlarm() { |
Jian Li | 9d61649 | 2016-03-09 10:52:49 -0800 | [diff] [blame] | 67 | WebTarget wt = target(); |
| 68 | String response = wt.path("/alarms/1").request().get(String.class); |
kmcpeake | 4fe18c8 | 2015-11-17 20:07:39 +0000 | [diff] [blame] | 69 | // Ensure hard-coded alarms returned okay |
| 70 | assertThat(response, containsString("\"NE is not reachable\",")); |
| 71 | assertThat(response, not(containsString("\"Equipment Missing\","))); |
| 72 | } |
| 73 | |
| 74 | } |