00001 /* 00002 * Copyright (C) 2011 Google Inc. 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); you may not 00005 * use this file except in compliance with the License. You may obtain a copy of 00006 * the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 00012 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 00013 * License for the specific language governing permissions and limitations under 00014 * the License. 00015 */ 00016 00017 package com.github.rosjava.rosjava_extras.hokuyo; 00018 00019 import static org.junit.Assert.assertTrue; 00020 00021 00022 import org.junit.After; 00023 import org.junit.Before; 00024 import org.junit.Test; 00025 import org.ros.RosCore; 00026 import org.ros.node.DefaultNodeMainExecutor; 00027 import org.ros.node.NodeConfiguration; 00028 import org.ros.node.NodeMainExecutor; 00029 00030 import java.util.concurrent.CountDownLatch; 00031 import java.util.concurrent.TimeUnit; 00032 00036 public class LaserScanPublisherIntegrationTest { 00037 00038 private NodeMainExecutor nodeMainExecutor; 00039 private RosCore rosCore; 00040 private NodeConfiguration nodeConfiguration; 00041 00042 @Before 00043 public void before() throws InterruptedException { 00044 rosCore = RosCore.newPrivate(); 00045 rosCore.start(); 00046 assertTrue(rosCore.awaitStart(1, TimeUnit.SECONDS)); 00047 nodeConfiguration = NodeConfiguration.newPrivate(rosCore.getUri()); 00048 nodeMainExecutor = DefaultNodeMainExecutor.newDefault(); 00049 } 00050 00051 @After 00052 public void after() { 00053 nodeMainExecutor.shutdown(); 00054 rosCore.shutdown(); 00055 } 00056 00057 @Test 00058 public void testLaserScanPublisher() throws InterruptedException { 00059 FakeLaserDevice fakeLaserDevice = new FakeLaserDevice(3); 00060 LaserScanPublisher laserScanPublisher = new LaserScanPublisher(fakeLaserDevice); 00061 nodeMainExecutor.execute(laserScanPublisher, nodeConfiguration); 00062 00063 final CountDownLatch latch = new CountDownLatch(1); 00064 LaserScanSubscriber laserScanSubscriber = new LaserScanSubscriber(latch); 00065 nodeMainExecutor.execute(laserScanSubscriber, nodeConfiguration); 00066 assertTrue(latch.await(1, TimeUnit.SECONDS)); 00067 00068 fakeLaserDevice.shutdown(); 00069 } 00070 }