Permalink
Browse files

Added EndpointAssignment integration test project

  • Loading branch information...
1 parent d2ea10a commit ebaeb430a0568f6ddf003d45f7282956b66f462e @samhendley samhendley committed Apr 18, 2012
View
81 integration-testing/endpoint-assignment/pom.xml
@@ -0,0 +1,81 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>reef-integration-endpoint-assignment</artifactId>
+ <parent>
+ <groupId>org.totalgrid.reef</groupId>
+ <artifactId>reef-integration-testing</artifactId>
+ <version>0.4.8-SNAPSHOT</version>
+ <relativePath>../</relativePath>
+ </parent>
+
+ <licenses>
+ <license>
+ <name>Apache 2</name>
+ <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
+ <comments>A business-friendly OSS license</comments>
+ </license>
+ </licenses>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>com.mycila.maven-license-plugin</groupId>
+ <artifactId>maven-license-plugin</artifactId>
+ <configuration>
+ <header>../../APACHE_FILE_HEADER</header>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ <profiles>
+ <profile>
+ <id>no_integration_testing</id>
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <excludes>
+ <exclude>**/*.java</exclude>
+ </excludes>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+ </profile>
+
+ <profile>
+ <id>test</id>
+ <activation>
+ <activeByDefault>true</activeByDefault>
+ </activation>
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>test</id>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+ </profiles>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.totalgrid.reef</groupId>
+ <artifactId>reef-integration-testing-tools</artifactId>
+ <version>${reef.version}</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+</project>
+
+
View
111 ...nment/src/test/scala/org/totalgrid/reef/protocol/integration/EndpointAssignmentTest.scala
@@ -0,0 +1,111 @@
+/**
+ * Copyright 2011 Green Energy Corp.
+ *
+ * Licensed to Green Energy Corp (www.greenenergycorp.com) under one or more
+ * contributor license agreements. See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership. Green Energy
+ * Corp licenses this file to you 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 org.totalgrid.reef.protocol.integration
+
+import org.junit.runner.RunWith
+import org.scalatest.junit.JUnitRunner
+
+import scala.collection.JavaConversions._
+
+import org.totalgrid.reef.client.sapi.rpc.impl.util.{ EndpointConnectionStateMap, ServiceClientSuite }
+import org.totalgrid.reef.client.exception.BadRequestException
+import org.totalgrid.reef.client.service.proto.FEP.{ FrontEndProcessor, EndpointConnection }
+
+@RunWith(classOf[JUnitRunner])
+class EndpointAssignmentTest extends ServiceClientSuite {
+
+ test("Check Endpoints Start Online and Assigned") {
+
+ val result = client.subscribeToEndpointConnections()
+ val map = new EndpointConnectionStateMap(result)
+ map.checkAllState(true, EndpointConnection.State.COMMS_UP)
+
+ val benchmarkAdapter = findProtocolAdapter(_ == "benchmark")
+
+ val connections = client.getEndpointConnections()
+ endpointsAssignedTo(connections, benchmarkAdapter)
+ endpointStateIs(connections, EndpointConnection.State.COMMS_UP)
+ }
+
+ test("Try claiming endpoint that is auto assigned") {
+
+ val notBenchmarkAdapter = findProtocolAdapter(_ != "benchmark")
+
+ val endpoints = client.getEndpoints()
+ endpoints.foreach { endpoint =>
+ intercept[BadRequestException] {
+ client.setEndpointConnectionAssignedProtocolAdapter(endpoint.getUuid, notBenchmarkAdapter.getUuid)
+ }
+ }
+ }
+
+ test("Switch endpoints to manually assigned") {
+
+ val endpoints = client.getEndpoints()
+
+ endpoints.map { _.getAutoAssigned }.distinct should equal(List(true))
+
+ endpoints.foreach { e => client.setEndpointAutoAssigned(e.getUuid, false) }
+
+ val connections = client.getEndpointConnections()
+ connections.map { _.hasFrontEnd } should equal(connections.map { c => false })
+ endpointStateIs(connections, EndpointConnection.State.COMMS_DOWN)
+ }
+
+ test("Claim endpoints for the wrong protocol adapter and check for errors") {
+
+ val notBenchmarkAdapter = findProtocolAdapter(_ == "dnp3")
+
+ val endpoints = client.getEndpoints()
+ endpoints.foreach { endpoint =>
+ client.setEndpointConnectionAssignedProtocolAdapter(endpoint.getUuid, notBenchmarkAdapter.getUuid)
+ }
+
+ val result = client.subscribeToEndpointConnections()
+ val map = new EndpointConnectionStateMap(result)
+ map.checkAllState(true, EndpointConnection.State.ERROR)
+ }
+
+ test("Switch endpoints back to auto assigned") {
+
+ val endpoints = client.getEndpoints()
+
+ endpoints.map { _.getAutoAssigned }.distinct should equal(List(false))
+
+ endpoints.foreach { e => client.setEndpointAutoAssigned(e.getUuid, true) }
+
+ val result = client.subscribeToEndpointConnections()
+ val map = new EndpointConnectionStateMap(result)
+ map.checkAllState(true, EndpointConnection.State.COMMS_UP)
+ }
+
+ private def findProtocolAdapter(fun: String => Boolean): FrontEndProcessor = {
+ val adapters = client.getProtocolAdapters()
+
+ val adapter = adapters.find(_.getProtocolsList.toList.find(fun).isDefined)
+ adapter should not equal (None)
+ adapter.get
+ }
+ private def endpointsAssignedTo(connections: List[EndpointConnection], fep: FrontEndProcessor) {
+ connections.map { _.getFrontEnd.getAppConfig.getInstanceName } should equal(connections.map { c => fep.getAppConfig.getInstanceName })
+ }
+ private def endpointStateIs(connections: List[EndpointConnection], state: EndpointConnection.State) {
+ connections.map { _.getState } should equal(connections.map { c => state })
+ }
+}
View
1 integration-testing/pom.xml
@@ -18,6 +18,7 @@
<modules>
<module>testing-tools</module>
<module>basic-system-tests</module>
+ <module>endpoint-assignment</module>
<module>protocol-dnp3</module>
<module>protocol-calculator</module>
<module>model-loading</module>

0 comments on commit ebaeb43

Please sign in to comment.