// Copyright 2014-2015 Boundary, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package com.boundary.sdk.event.script;
import static org.junit.Assert.*;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Calendar.Builder;
import java.util.Date;
import java.util.List;
import java.util.Map;
import org.apache.camel.EndpointInject;
import org.apache.camel.Exchange;
import org.apache.camel.Message;
import org.apache.camel.Produce;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.test.spring.CamelSpringTestSupport;
import org.junit.Test;
import org.snmp4j.smi.OID;
import org.snmp4j.smi.TimeTicks;
import org.snmp4j.smi.Counter64;
import org.snmp4j.smi.Counter32;
import org.snmp4j.smi.Gauge32;
import org.snmp4j.smi.UnsignedInteger32;
import org.snmp4j.smi.Variable;
import org.snmp4j.smi.VariableBinding;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.boundary.sdk.event.RawEvent;
import com.boundary.sdk.event.snmp.SendTrap;
import com.boundary.sdk.event.snmp.SnmpPollerConfiguration;
import com.boundary.sdk.event.snmp.entry;
import com.boundary.sdk.metric.Measurement;
import com.boundary.sdk.snmp.metric.OidMap;
import static com.boundary.sdk.event.script.ScriptTestUtils.*;
public class SnmpToEventTest extends CamelSpringTestSupport {
@Produce(uri = "direct:in")
private ProducerTemplate in;
@EndpointInject(uri = "mock:out")
private MockEndpoint out;
private SendTrap trap;
@Override
public void setUp() throws Exception {
super.setUp();
trap = new SendTrap();
trap.setPort(1162);
}
@Test
public void testTranslatedEvent() throws Exception {
out.expectedMinimumMessageCount(1);
trap.send();
out.assertIsSatisfied();
List<Exchange> exchanges = out.getExchanges();
Exchange exchange = exchanges.get(0);
Message message = exchange.getIn();
RawEvent event = message.getBody(RawEvent.class);
assertNotNull("check for not null",event);
assertEquals("check event title","linkDown trap received from 127.0.0.1",event.getTitle());
assertEquals("check event message","Received linkDown trap",event.getMessage());
Map<String,Object> properties = event.getProperties();
assertEquals("check trap property","Host has been restarted",properties.get("linkDown"));
assertEquals("check uptime property","7:12:00.00",properties.get("sysUpTimeInstance"));
assertEquals("check description property","Test Trap!",properties.get("sysDescr.0"));
}
@Override
protected AbstractApplicationContext createApplicationContext() {
return new ClassPathXmlApplicationContext("META-INF/spring/test-snmp-to-event.xml");
}
}