From: Xia Yin Ben Date: Mon, 18 Jan 2016 02:18:01 +0000 (+0000) Subject: Merge "delete all .class files" into stable/beryllium X-Git-Tag: release/beryllium~9 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=c82427e3e217c44f189c284f9469ca5ac362a2bd;hp=fea37d42b1eeb5c8beb16357327054397bbc52c0;p=nemo.git Merge "delete all .class files" into stable/beryllium --- diff --git a/nemo-impl/src/test/java/org/opendaylight/nemo/intent/IntentResolverTest.java b/nemo-impl/src/test/java/org/opendaylight/nemo/intent/IntentResolverTest.java new file mode 100644 index 0000000..56e0a80 --- /dev/null +++ b/nemo-impl/src/test/java/org/opendaylight/nemo/intent/IntentResolverTest.java @@ -0,0 +1,412 @@ +/* + * Copyright (c) 2016 Huawei, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.nemo.intent; + +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.*; +import com.google.common.base.Optional; +import org.opendaylight.controller.md.sal.binding.api.DataBroker; +import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction; +import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; +import org.opendaylight.nemo.intent.computation.PNComputationUnit; +import org.opendaylight.nemo.intent.computation.PNResourcesTracker; +import org.opendaylight.nemo.intent.computation.VNComputationUnit; +import org.opendaylight.nemo.intent.computation.VNMappingUnit; +import org.opendaylight.nemo.intent.condition.ConditionManager; +import org.opendaylight.nemo.user.vnspacemanager.structurestyle.updateintent.UpdateIntent; +import org.opendaylight.nemo.user.vnspacemanager.structurestyle.updateintent.UpdateNode; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.PhysicalNetwork; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.network.PhysicalPaths; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.network.physical.paths.PhysicalPath; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.network.physical.paths.PhysicalPathKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.virtual.network.rev151010.VirtualNetworks; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.virtual.network.rev151010.virtual.networks.VirtualNetwork; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.virtual.network.rev151010.virtual.networks.VirtualNetworkBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.virtual.network.rev151010.virtual.networks.VirtualNetworkKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.virtual.network.rev151010.virtual.networks.virtual.network.*; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.virtual.network.rev151010.virtual.networks.virtual.network.virtual.arps.VirtualArp; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.virtual.network.rev151010.virtual.networks.virtual.network.virtual.links.VirtualLink; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.virtual.network.rev151010.virtual.networks.virtual.network.virtual.nodes.VirtualNode; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.virtual.network.rev151010.virtual.networks.virtual.network.virtual.paths.VirtualPath; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.virtual.network.rev151010.virtual.networks.virtual.network.virtual.routes.VirtualRoute; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.intent.mapping.result.rev151010.IntentVnMappingResults; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.intent.mapping.result.rev151010.VnPnMappingResults; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.intent.mapping.result.rev151010.intent.vn.mapping.results.UserIntentVnMapping; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.intent.mapping.result.rev151010.intent.vn.mapping.results.UserIntentVnMappingBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.intent.mapping.result.rev151010.intent.vn.mapping.results.UserIntentVnMappingKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.intent.mapping.result.rev151010.intent.vn.mapping.results.user.intent.vn.mapping.IntentVnMappingResult; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.intent.mapping.result.rev151010.vn.pn.mapping.results.UserVnPnMapping; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.intent.mapping.result.rev151010.vn.pn.mapping.results.UserVnPnMappingBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.intent.mapping.result.rev151010.vn.pn.mapping.results.UserVnPnMappingKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.intent.mapping.result.rev151010.vn.pn.mapping.results.user.vn.pn.mapping.VnPnMappingResult; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.common.rev151010.NodeType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.common.rev151010.UserId; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.engine.common.rev151010.PhysicalPathId; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.engine.common.rev151010.VirtualNetworkId; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.Users; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.user.intent.objects.Connection; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.user.intent.objects.Flow; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.user.intent.objects.Node; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.user.intent.Objects; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.user.intent.operations.Operation; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.users.User; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.users.UserKey; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.concurrent.ExecutionException; + +import java.util.List; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.LinkedList; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import java.util.*; +import java.util.List; + +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.network.PhysicalLinks; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.network.PhysicalNodes; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; +import com.google.common.util.concurrent.CheckedFuture; +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.List; +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; +import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.user.intent.Operations; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.user.intent.Results; +import static org.junit.Assert.*; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.intent.mapping.result.rev151010.VirtualResourceInstance.VirtualResourceType; +import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.engine.common.rev151010.PhysicalResourceEntityId; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.engine.common.rev151010.PhysicalNodeId; +import org.mockito.Mockito; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.api.support.membermodification.MemberMatcher; +import org.powermock.api.support.membermodification.MemberModifier; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.common.rev151010.ObjectId; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.network.PhysicalHosts; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.network.physical.hosts.PhysicalHost; +import static org.mockito.Mockito.doNothing; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.common.rev151010.NodeId; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.object.rev151010.node.instance.Property; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.object.rev151010.property.instance.property.values.StringValue; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.object.rev151010.property.instance.PropertyValues; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.common.rev151010.PropertyName; +/** + * Created by ldzd11 on 2015/12/24. + */ + +@RunWith(PowerMockRunner.class) +@PrepareForTest(IntentResolverUtils.class) +public class IntentResolverTest { + private IntentResolver intentResolver; + private DataBroker dataBroker; + private UserId userId; + private List vnPnMappingResults; + private VnPnMappingResult vnPnMappingResult; + private VirtualResourceType virtualResourceType; + private PhysicalResourceEntityId physicalResourceEntityId; + private Objects objects; + private List nodeList; + private Node node; + private NodeType nodeType; + private List connections; + private Connection connection; + private List flows; + private Flow flow; + private Operations operations; + private List operationList; + private Operation operation; + private ObjectId objectId; + private NodeId nodeId; + private List physicalHostList; + private PhysicalHost physicalHost; + private Property property; + private List propertyList; + private PropertyValues propertyValues; + private StringValue stringValue; + private List stringValueList; + + + @Before + public void setUp() throws Exception { + dataBroker = mock(DataBroker.class); + userId = mock(UserId.class); + + vnPnMappingResults = new ArrayList(); + vnPnMappingResult = mock(VnPnMappingResult.class); + vnPnMappingResults.add(vnPnMappingResult); + + virtualResourceType = VnPnMappingResult.VirtualResourceType.Vlink; + physicalResourceEntityId =mock(PhysicalResourceEntityId.class); + objects = mock(Objects.class); + nodeList = new ArrayList(); + node = mock(Node.class); + nodeList.add(node); + nodeType = mock(NodeType.class); + connections = new ArrayList(); + connection = mock(Connection.class); + connections.add(connection); + flows = new ArrayList(); + flow = mock(Flow.class); + flows.add(flow); + operations = mock(Operations.class); + operationList = new ArrayList(); + operation = mock(Operation.class); + operationList.add(operation); + objectId = mock(ObjectId.class); + nodeId = mock(NodeId.class); + + physicalHostList = new ArrayList(); + physicalHost = mock(PhysicalHost.class); + physicalHostList.add(physicalHost); + property = mock(Property.class); + propertyList = new ArrayList(); + propertyList.add(property); + propertyValues = mock(PropertyValues.class); + stringValueList = new ArrayList(); + stringValue = mock(StringValue.class); + stringValueList.add(stringValue); + + + + + //into PNC to result + ReadOnlyTransaction readOnlyTransaction = mock(ReadOnlyTransaction.class); + when(dataBroker.newReadOnlyTransaction()).thenReturn(readOnlyTransaction); + + CheckedFuture physicalnodesFuture = mock(CheckedFuture.class); + CheckedFuture physicallinksFuture = mock(CheckedFuture.class); + when(readOnlyTransaction.read(any(LogicalDatastoreType.class), any(InstanceIdentifier.class))).thenReturn(physicalnodesFuture).thenReturn(physicallinksFuture); + + //////////////////first result///////////////////// + PhysicalNodes physicalNodes = mock(PhysicalNodes.class); + Optional result = Optional.of(physicalNodes); + Assert.assertTrue(result.isPresent()); + when(physicalnodesFuture.get()).thenReturn(result); + + ///////////////////Second result/////////////////////// + PhysicalLinks physicalLinks = mock(PhysicalLinks.class); + Optional result1 = Optional.of(physicalLinks); + Assert.assertTrue(result1.isPresent()); + when(physicallinksFuture.get()).thenReturn(result1); + + intentResolver = new IntentResolver(dataBroker); + } + + @Test + public void testResolveIntent() throws Exception { + PowerMockito.mockStatic(IntentResolverUtils.class); + PowerMockito.doNothing().when(IntentResolverUtils.class); + IntentResolverUtils.copyPhysicalNetworkConfigToOperational(dataBroker); + + Class class1 = IntentResolver.class; + + CheckedFuture userVnPnMappingIidFuture = mock(CheckedFuture.class); + CheckedFuture userFuture = mock(CheckedFuture.class); + CheckedFuture physicalHostsFuture = mock(CheckedFuture.class); + + ReadWriteTransaction readWriteTransaction = mock(ReadWriteTransaction.class); + when(dataBroker.newReadWriteTransaction()).thenReturn(readWriteTransaction); + ReadOnlyTransaction readOnlyTransaction = mock(ReadOnlyTransaction.class); + when(dataBroker.newReadOnlyTransaction()).thenReturn(readOnlyTransaction); + + when(readWriteTransaction.read(any(LogicalDatastoreType.class), any(InstanceIdentifier.class))).thenReturn(userVnPnMappingIidFuture).thenReturn(userFuture); + when(readOnlyTransaction.read(any(LogicalDatastoreType.class), any(InstanceIdentifier.class))).thenReturn(physicalHostsFuture); + + + when(userId.getValue()).thenReturn(new String("00001111-0000-0000-0000-000011112222")); + //////////////152 forvnComputationUnits.get(userId) into if null != vnComputationUnit + Map vnComputationUnits = new HashMap(); + VNComputationUnit vnComputationUnit = mock(VNComputationUnit.class); + vnComputationUnits.put(userId, vnComputationUnit); + + Field field1 = class1.getDeclaredField("vnComputationUnits"); + field1.setAccessible(true); + field1.set(intentResolver, vnComputationUnits);//for 170 + //into null!=vncomputionUnit + + ////////////////////the result1//////////////////////// + UserVnPnMapping userVnPnMapping = mock(UserVnPnMapping.class); + Optional result1 = Optional.of(userVnPnMapping); + Assert.assertTrue(result1.isPresent()); + when(userVnPnMappingIidFuture.get()).thenReturn(result1); + + //187 into result1.is present + when(userVnPnMapping.getVnPnMappingResult()).thenReturn(vnPnMappingResults); + when(vnPnMappingResult.getVirtualResourceType()).thenReturn(virtualResourceType); + when(vnPnMappingResult.getPhysicalResourceEntityId()).thenReturn(physicalResourceEntityId); + when(vnPnMappingResult.getPhysicalResourceEntityId().getValue()).thenReturn(new String("00001111-0000-0000-0000-000011112222")); + + //end of 212 + //////////////////the result2//////////////////////////////// + User user = mock(User.class); + Optional result2 = Optional.of(user); + Assert.assertTrue(result2.isPresent()); + when(userFuture.get()).thenReturn(result2); + + ////////into null!-user.getObjects + when(user.getObjects()).thenReturn(objects); + when(user.getObjects().getNode()).thenReturn(nodeList); + ////////////////////1///////////////////////////////// + nodeType = new NodeType("host"); + when(node.getNodeType()).thenReturn(nodeType); + ////////////////////into nodeMapper.resolverHosr for nodes + NodeMapper nodeMapper = mock(NodeMapper.class); + Field field2 = class1.getDeclaredField("nodeMapper"); + field2.setAccessible(true); + field2.set(intentResolver, nodeMapper);//for 170 + doNothing().when(nodeMapper).resolveHost(any(User.class), any(Node.class), any(VirtualNetwork.class), any(UserIntentVnMapping.class)); + + ///////////////////2////////////////////////////// + nodeType = new NodeType("l2-group"); + when(node.getNodeType()).thenReturn(nodeType); + ////////////////////into nodeMapper.resolverHosr for nodes + doNothing().when(nodeMapper).resolveLayer2Group(any(User.class), any(Node.class), any(VirtualNetwork.class), any(UserIntentVnMapping.class)); + + //////////////////////3/////////////////////////////// + nodeType = new NodeType("l3-group"); + when(node.getNodeType()).thenReturn(nodeType); + ////////////////////into nodeMapper.resolverHosr for nodes + doNothing().when(nodeMapper).resolveLayer3Group(any(User.class), any(Node.class), any(VirtualNetwork.class), any(UserIntentVnMapping.class)); + + //////////////////////4/////////////////////////////// + nodeType = new NodeType("ext-group"); + when(node.getNodeType()).thenReturn(nodeType); + ////////////////////into nodeMapper.resolverHosr for nodes + when(node.getProperty()).thenReturn(propertyList); + PropertyName propertyName = new PropertyName("ac-info-network"); + when(property.getPropertyName()).thenReturn(propertyName); + when(property.getPropertyValues()).thenReturn(propertyValues); + when(property.getPropertyValues().getStringValue()).thenReturn(stringValueList); + when(property.getPropertyValues().getStringValue().get(0).getValue()).thenReturn(new String("layer3")); + doNothing().when(nodeMapper).resolveExternalLayer3Group(any(User.class), any(Node.class), any(VirtualNetwork.class), any(UserIntentVnMapping.class)); + + //////////////////////5/////////////////////////////// + nodeType = new NodeType("chain-group"); + when(node.getNodeType()).thenReturn(nodeType); + ////////////////////into nodeMapper.resolverHosr for nodes + doNothing().when(nodeMapper).resolveServiceChainGroup(any(User.class), any(Node.class), any(VirtualNetwork.class), any(UserIntentVnMapping.class)); + + //////////////////////6/////////////////////////////// + nodeType = new NodeType("fw"); + when(node.getNodeType()).thenReturn(nodeType); + ////////////////////into nodeMapper.resolverHosr for nodes + doNothing().when(nodeMapper).resolveServiceFunction(any(User.class), any(Node.class), any(VirtualNetwork.class), any(UserIntentVnMapping.class)); + + //////////////////////6/////////////////////////////// + nodeType = new NodeType("lb"); + when(node.getNodeType()).thenReturn(nodeType); + ////////////////////into nodeMapper.resolverHosr for nodes + doNothing().when(nodeMapper).resolveServiceFunction(any(User.class), any(Node.class), any(VirtualNetwork.class), any(UserIntentVnMapping.class)); + + //////////////////////6/////////////////////////////// + nodeType = new NodeType("cache"); + when(node.getNodeType()).thenReturn(nodeType); + ////////////////////into nodeMapper.resolverHosr for nodes + doNothing().when(nodeMapper).resolveServiceFunction(any(User.class), any(Node.class), any(VirtualNetwork.class), any(UserIntentVnMapping.class)); + + + //////////////////////connection/////////////////////////// + when(user.getObjects().getConnection()).thenReturn(connections); + ConnectionMapper connectionMapper = mock(ConnectionMapper.class); + Field field4 = class1.getDeclaredField("connectionMapper"); + field4.setAccessible(true); + field4.set(intentResolver, connectionMapper);//for 170 + doNothing().when(connectionMapper).resolveConnection(any(User.class), any(Connection.class), any(VirtualNetwork.class), any(UserIntentVnMapping.class)); + + //////////////////////flow/////////////////////////// + when(user.getObjects().getFlow()).thenReturn(flows); + //////////////////////operation/////////////////////////// + when(user.getOperations()).thenReturn(operations); + when(user.getOperations().getOperation()).thenReturn(operationList); + + + //into operationResolver.classifyOperations + OperationResolver operationResolver =mock(OperationResolver.class); + Field field3 = class1.getDeclaredField("operationResolver"); + field3.setAccessible(true); + field3.set(intentResolver, operationResolver); + doNothing().when(operationResolver).classifyOperations(any(User.class), any(List.class), any(List.class), any(List.class), any(List.class)); + doNothing().when(operationResolver).resolveOperation(any(User.class), any(Operation.class), any(VirtualNetwork.class), any(UserIntentVnMapping.class)); + + //392vnMappingUnit + VNMappingUnit vnMappingUnit = mock(VNMappingUnit.class); + Field field5 = class1.getDeclaredField("vnMappingUnit"); + field5.setAccessible(true); + field5.set(intentResolver, vnMappingUnit);//for 170 + doNothing().when(vnMappingUnit).virtualNetworkMapping(any(VirtualNetwork.class), any(UserVnPnMapping.class), any(List.class)); + + intentResolver.resolveIntent(userId); + + } + + @Test + public void testClose() throws Exception { + Class class1 = IntentResolver.class; + PNComputationUnit pnComputationUnit = mock(PNComputationUnit.class); + + VNComputationUnit vnComputationUnit = mock(VNComputationUnit.class); + Map vnComputationUnits = new HashMap(); + vnComputationUnits.put(userId,vnComputationUnit); + + PNResourcesTracker pnResourcesTracker = mock(PNResourcesTracker.class); + VNMappingUnit vnMappingUnit = mock(VNMappingUnit.class); + + + Field field1 = class1.getDeclaredField("pnComputationUnit"); + field1.setAccessible(true); + field1.set(intentResolver, pnComputationUnit); + + Field field2 = class1.getDeclaredField("vnComputationUnits"); + field2.setAccessible(true); + field2.set(intentResolver, vnComputationUnits); + + Field field3 = class1.getDeclaredField("pnResourcesTracker"); + field3.setAccessible(true); + field3.set(intentResolver, pnResourcesTracker); + + Field field4 = class1.getDeclaredField("vnMappingUnit"); + field4.setAccessible(true); + field4.set(intentResolver, vnMappingUnit); + + intentResolver.close(); + + } +} \ No newline at end of file diff --git a/nemo-impl/src/test/java/org/opendaylight/nemo/intent/action/ActionResolverTest.java b/nemo-impl/src/test/java/org/opendaylight/nemo/intent/action/ActionResolverTest.java index 80c8781..88014a8 100644 --- a/nemo-impl/src/test/java/org/opendaylight/nemo/intent/action/ActionResolverTest.java +++ b/nemo-impl/src/test/java/org/opendaylight/nemo/intent/action/ActionResolverTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Huawei, Inc. and others. All rights reserved. + * Copyright (c) 2016 Huawei, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, @@ -19,9 +19,11 @@ import static org.junit.Assert.*; import java.io.*; //import java.util.*; +import org.junit.runner.RunWith; import org.opendaylight.controller.md.sal.binding.api.DataBroker; import org.opendaylight.nemo.intent.IntentResolutionException; import org.opendaylight.nemo.intent.IntentResolverUtils; +import org.opendaylight.nemo.intent.NodeMapper; import org.opendaylight.nemo.intent.computation.VNComputationUnit; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.virtual.network.rev151010.virtual.networks.VirtualNetwork; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.virtual.network.rev151010.virtual.networks.virtual.network.virtual.links.VirtualLink; @@ -62,6 +64,11 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.obj import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.api.support.membermodification.MemberMatcher; +import org.powermock.api.support.membermodification.MemberModifier; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; import javax.lang.model.type.ArrayType; //import java.sql.Connection; @@ -69,11 +76,16 @@ import java.lang.reflect.Array; import java.util.*; import java.lang.*; +import java.lang.reflect.Method; +import java.lang.reflect.Field; + /** * Created by Thomas Liu on 2015/12/7. */ +@RunWith(PowerMockRunner.class) +@PrepareForTest({ActionResolverUtils.class,IntentResolverUtils.class}) public class ActionResolverTest extends TestCase { private ActionResolver actionResolverTest; @@ -87,6 +99,7 @@ public class ActionResolverTest extends TestCase { private Flow flow; private VirtualNetwork virtualNetwork; private UserIntentVnMapping userIntentVnMapping; + private UserId userId ; List actions; private Action action; @@ -104,6 +117,9 @@ public class ActionResolverTest extends TestCase { private VirtualLinks virtualLink; private List virtualLinks; private VirtualResourceEntityId virtualResourceEntityId; + private Class class1; + private Method method; + private Field field; //deny @@ -134,9 +150,10 @@ public class ActionResolverTest extends TestCase { @org.junit.Before public void setUp() throws Exception { + userId = new UserId("11111111-1111-1111-1111-111111111111"); dataBroker = mock(DataBroker.class); vnComputationUnits = new HashMap(); - vnComputationUnits.put(mock(UserId.class), mock(VNComputationUnit.class)); + vnComputationUnits.put(userId, mock(VNComputationUnit.class)); actionResolverTest = new ActionResolver(dataBroker,vnComputationUnits); @@ -149,6 +166,7 @@ public class ActionResolverTest extends TestCase { userIntentVnMapping = mock(UserIntentVnMapping.class); + actions = new ArrayList(); actions.add(mock(Action.class)); parameterValues1 = new ArrayList(){{ add(mock(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.operation.rev151010.action.instance.parameter.values.IntValue.class)); }}; @@ -188,188 +206,153 @@ public class ActionResolverTest extends TestCase { subNodes = new ArrayList(){{add(mock(SubNode.class));}}; virtualPorts1 = new ArrayList(); virtualPorts2 = new ArrayList(); + class1 = ActionResolver.class; } @org.junit.Test public void testResolveActions() throws Exception { actionResolverTest.resolveActions(user,operation,node,virtualNetwork, userIntentVnMapping); - } @org.junit.Test public void testResolveActions1() throws Exception { when(operation.getAction()).thenReturn(actions); - when(actions.get(0).getActionName()).thenReturn(new ActionName("qos-bandwidth")); - action = actions.get(0); - when(action.getParameterValues()).thenReturn(parametervalues); + Action qosBandwidthAction = mock(Action.class); + PowerMockito.mockStatic(ActionResolverUtils.class); + PowerMockito.when(ActionResolverUtils.getAction(any(List.class), any(ActionName.class))).thenReturn(qosBandwidthAction); + //test resolveQosBandwidthAction() + when(qosBandwidthAction.getParameterValues()).thenReturn(parametervalues); when(parametervalues.getIntValue()).thenReturn(parameterValues1); - intValue1 = parameterValues1.get(0); - when(intValue1.getValue()).thenReturn(new Long(1)); + IntValue parameterValue = parameterValues1.get(0); + when(parameterValue.getValue()).thenReturn(1L); when(connection.getProperty()).thenReturn(properties); - when(properties.get(0).getPropertyName()).thenReturn(new PropertyName("bandwidth")); - property2 = properties.get(0); - when(property2.getPropertyValues()).thenReturn(propertyValues); + Property property = mock(Property.class); + PowerMockito.mockStatic(IntentResolverUtils.class); + PowerMockito.when(IntentResolverUtils.getConnectionProperty(any(List.class), any(PropertyName.class))).thenReturn(property); + when(property.getPropertyValues()).thenReturn(propertyValues); when(propertyValues.getIntValue()).thenReturn(parameterValues2); intValue2 = parameterValues2.get(0); - when(intValue2.getValue()).thenReturn(new Long(2)); + when(intValue2.getValue()).thenReturn(2L); when(userIntentVnMapping.getIntentVnMappingResult()).thenReturn(intentVnMappingResults); + IntentVnMappingResult intentVnMappingResult = mock(IntentVnMappingResult.class); when(connection.getConnectionId()).thenReturn(connectionId); - when(intentVnMappingResults.get(0).getIntentId()).thenReturn(new IntentId(connectionId)); - when(intentVnMappingResults.get(0).getVirtualResource()).thenReturn(virtualResources); + PowerMockito.when(IntentResolverUtils.getIntentVnMappingResult(any(List.class), any(IntentId.class))).thenReturn(intentVnMappingResult); + when(intentVnMappingResult.getVirtualResource()).thenReturn(virtualResources); when(virtualNetwork.getVirtualLinks()).thenReturn(virtualLink); when(virtualLink.getVirtualLink()).thenReturn(virtualLinks); when(virtualResources.get(0).getVirtualResourceEntityId()).thenReturn(virtualResourceEntityId); when(virtualResourceEntityId.getValue()).thenReturn("11111111-1111-1111-1111-111111111111"); when(virtualLinks.get(0).getLinkId()).thenReturn(new VirtualLinkId("11111111-1111-1111-1111-111111111111")); actionResolverTest.resolveActions(user,operation,connection,virtualNetwork, userIntentVnMapping); - } @org.junit.Test public void testResolveActionsDeny() throws Exception { - //deny when(operation.getAction()).thenReturn(actions); - when(actions.get(0).getActionName()).thenReturn(new ActionName("deny")); + Action denyAction = mock(Action.class); + PowerMockito.mockStatic(ActionResolverUtils.class); + PowerMockito.when(ActionResolverUtils.getAction(any(List.class), any(ActionName.class))).thenReturn(denyAction); when(user.getObjects()).thenReturn(objects); when(objects.getNode()).thenReturn(nodes); when(virtualNetwork.getVirtualNodes()).thenReturn(virtualNode); when(virtualNode.getVirtualNode()).thenReturn(virtualNodes); when(userIntentVnMapping.getIntentVnMappingResult()).thenReturn(intentVnMappingResults); - when(flow.getMatchItem()).thenReturn(matchItem);//matchItem - when(matchItem.get(0).getMatchItemName()).thenReturn(new MatchItemName("src-ip")); - when(matchItem.get(0).getMatchItemValue()).thenReturn(matchItemValue);//matchItemValue - when(matchItemValue.getStringValue()).thenReturn(new String("src-ip")); - when(nodes.get(0).getNodeType()).thenReturn(new NodeType("l2-group")); - when(nodes.get(0).getProperty()).thenReturn(properties2); - when(properties2.get(0).getPropertyName()).thenReturn(new PropertyName("ip-prefix")); - when(properties2.get(0).getPropertyValues()).thenReturn(propertyValues); - when(propertyValues.getStringValue()).thenReturn(stringValue); - when(stringValue.get(0).getValue()).thenReturn(new String("src-ip")); - when(nodes.get(0).getNodeId()).thenReturn(nodeId); - when(nodeId.getValue()).thenReturn(new String("11111111-1111-1111-1111-111111111111")); - when(intentVnMappingResults.get(0).getIntentId()).thenReturn(new IntentId("11111111-1111-1111-1111-111111111111")); - when(intentVnMappingResults.get(0).getVirtualResource()).thenReturn(virtualResources); - when(virtualResources.get(0).getVirtualResourceType()).thenReturn(VirtualResource.VirtualResourceType.Vport); - when(virtualResources.get(0).getParentVirtualResourceEntityId()).thenReturn(virtualResourceEntityId); - when(virtualResourceEntityId.getValue()).thenReturn(new String("11111111-1111-1111-1111-111111111111")); - when(virtualNodes.get(0).getNodeId()).thenReturn(new VirtualNodeId("11111111-1111-1111-1111-111111111111")); - when(virtualNodes.get(0).getNodeType()).thenReturn(VirtualNode.NodeType.Vrouter); - - when(flow.getMatchItem()).thenReturn(matchItem);//matchItem - when(matchItem.get(0).getMatchItemName()).thenReturn(new MatchItemName("src-ip")); - when(matchItem.get(0).getMatchItemValue()).thenReturn(matchItemValue);//matchItemValue - when(matchItemValue.getStringValue()).thenReturn(new String("src-ip")); - when(nodes.get(0).getNodeType()).thenReturn(new NodeType("l2-group")); - when(nodes.get(0).getProperty()).thenReturn(properties2); - when(properties2.get(0).getPropertyName()).thenReturn(new PropertyName("ip-prefix")); - when(properties2.get(0).getPropertyValues()).thenReturn(propertyValues); - when(propertyValues.getStringValue()).thenReturn(stringValue); - when(stringValue.get(0).getValue()).thenReturn(new String("src-ip")); - when(nodes.get(0).getNodeId()).thenReturn(nodeId); - when(nodeId.getValue()).thenReturn(new String("11111111-1111-1111-1111-111111111111")); - when(intentVnMappingResults.get(0).getIntentId()).thenReturn(new IntentId("11111111-1111-1111-1111-111111111111")); - when(intentVnMappingResults.get(0).getVirtualResource()).thenReturn(virtualResources); - when(virtualResources.get(0).getVirtualResourceType()).thenReturn(VirtualResource.VirtualResourceType.Vport); - when(virtualResources.get(0).getParentVirtualResourceEntityId()).thenReturn(virtualResourceEntityId); - when(virtualResourceEntityId.getValue()).thenReturn(new String("11111111-1111-1111-1111-111111111111")); - when(virtualNodes.get(0).getNodeId()).thenReturn(new VirtualNodeId("11111111-1111-1111-1111-111111111111")); - when(virtualNodes.get(0).getNodeType()).thenReturn(VirtualNode.NodeType.Vrouter); - - when(virtualNodes.get(0).getNodeId()).thenReturn(new VirtualNodeId("11111111-1111-1111-1111-111111111111")); + VirtualNode sourceVirtualNode = mock(VirtualNode.class); + PowerMockito.when(ActionResolverUtils.getSourceVirtualRouterOfFlow(virtualNodes, flow, nodes, intentVnMappingResults)).thenReturn(sourceVirtualNode); + VirtualNode destinationVirtualNode = mock(VirtualNode.class); + PowerMockito.when(ActionResolverUtils.getDestinationVirtualRouterOfFlow(virtualNodes, flow, nodes, intentVnMappingResults)).thenReturn(destinationVirtualNode); + when(user.getUserId()).thenReturn(userId); + VNComputationUnit vnComputationUnit = vnComputationUnits.get(userId); + //List virtualPath = new ArrayList(){{ add(mock(VirtualPath.class));}}; + VirtualPath virtualPath = mock(VirtualPath.class); + VirtualNodeId vnodeIds = mock(VirtualNodeId.class); + VirtualNodeId vnodeIdd = mock(VirtualNodeId.class); + when(sourceVirtualNode.getNodeId()).thenReturn(vnodeIds); + when(destinationVirtualNode.getNodeId()).thenReturn(vnodeIdd); + when(vnComputationUnit.computePath(vnodeIds, vnodeIdd)).thenReturn(virtualPath); + List virtualLinks = new ArrayList(){{add(mock(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.virtual.network.rev151010.virtual.path.instance.VirtualLink.class));}}; + when(virtualPath.getVirtualLink()).thenReturn(virtualLinks); + VirtualPaths virtualPaths = mock(VirtualPaths.class); + List virtualPathList = new ArrayList(); + when(virtualNetwork.getVirtualPaths()).thenReturn(virtualPaths); + when(virtualPaths.getVirtualPath()).thenReturn(virtualPathList); + when(virtualPath.getPathId()).thenReturn(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.engine.common.rev151010.VirtualPathId("11111111-1111-1111-1111-111111111111")); when(operation.getOperationId()).thenReturn(new OperationId("11111111-1111-1111-1111-111111111111")); - //actionResolverTest.resolveActions(user,operation,flow,virtualNetwork, userIntentVnMapping); - - - - - - - + actionResolverTest.resolveActions(user,operation,flow,virtualNetwork, userIntentVnMapping); } - /*@org.junit.Test + @org.junit.Test public void testResolveActionsAllow() throws Exception { //allow when(operation.getAction()).thenReturn(actions); - when(actions.get(0).getActionName()).thenReturn(new ActionName("allow")); + Action allowAction = mock(Action.class); + PowerMockito.mockStatic(ActionResolverUtils.class); + PowerMockito.when(ActionResolverUtils.getAction(any(List.class), any(ActionName.class))).thenReturn(null); + PowerMockito.when(ActionResolverUtils.getAction(any(List.class), any(ActionName.class))).thenReturn(allowAction); + when(user.getObjects()).thenReturn(objects); when(objects.getNode()).thenReturn(nodes); when(virtualNetwork.getVirtualNodes()).thenReturn(virtualNode); when(virtualNode.getVirtualNode()).thenReturn(virtualNodes); when(userIntentVnMapping.getIntentVnMappingResult()).thenReturn(intentVnMappingResults); - - - - when(flow.getMatchItem()).thenReturn(matchItem);//matchItem - when(matchItem.get(0).getMatchItemName()).thenReturn(new MatchItemName("src-ip")); - when(matchItem.get(0).getMatchItemValue()).thenReturn(matchItemValue);//matchItemValue - when(matchItemValue.getStringValue()).thenReturn(new String("src-ip")); - when(nodes.get(0).getNodeType()).thenReturn(new NodeType("l2-group")); - when(nodes.get(0).getProperty()).thenReturn(properties2); - when(properties2.get(0).getPropertyName()).thenReturn(new PropertyName("ip-prefix")); - when(properties2.get(0).getPropertyValues()).thenReturn(propertyValues); - when(propertyValues.getStringValue()).thenReturn(stringValue); - when(stringValue.get(0).getValue()).thenReturn(new String("src-ip")); - when(nodes.get(0).getNodeId()).thenReturn(nodeId); - when(nodeId.getValue()).thenReturn(new String("11111111-1111-1111-1111-111111111111")); - when(intentVnMappingResults.get(0).getIntentId()).thenReturn(new IntentId("11111111-1111-1111-1111-111111111111")); - when(intentVnMappingResults.get(0).getVirtualResource()).thenReturn(virtualResources); - when(virtualResources.get(0).getVirtualResourceType()).thenReturn(VirtualResource.VirtualResourceType.Vport); - when(virtualResources.get(0).getParentVirtualResourceEntityId()).thenReturn(virtualResourceEntityId); - when(virtualResourceEntityId.getValue()).thenReturn(new String("11111111-1111-1111-1111-111111111111")); - System.out.println("1"); - when(virtualNodes.get(0).getNodeId()).thenReturn(new VirtualNodeId("11111111-1111-1111-1111-111111111111")); - System.out.println("2"); - when(virtualNodes.get(0).getNodeType()).thenReturn(VirtualNode.NodeType.Vrouter); - System.out.println("3"); - //when(flow.getFlowId()).thenReturn(new FlowId("11111111-1111-1111-1111-111111111111")); - - - - when(flow.getMatchItem()).thenReturn(matchItem);//matchItem - when(matchItem.get(0).getMatchItemName()).thenReturn(new MatchItemName("dst-ip")); - when(matchItem.get(0).getMatchItemValue()).thenReturn(matchItemValue);//matchItemValue - when(matchItemValue.getStringValue()).thenReturn(new String("dst-ip")); - when(nodes.get(0).getNodeType()).thenReturn(new NodeType("l2-group")); - when(nodes.get(0).getProperty()).thenReturn(properties2); - when(properties2.get(0).getPropertyName()).thenReturn(new PropertyName("ip-prefix")); - when(properties2.get(0).getPropertyValues()).thenReturn(propertyValues); - when(propertyValues.getStringValue()).thenReturn(stringValue); - when(stringValue.get(0).getValue()).thenReturn(new String("src-ip")); - when(nodes.get(0).getNodeId()).thenReturn(nodeId); - when(nodeId.getValue()).thenReturn(new String("11111111-1111-1111-1111-111111111111")); - when(intentVnMappingResults.get(0).getIntentId()).thenReturn(new IntentId("11111111-1111-1111-1111-111111111111")); - when(intentVnMappingResults.get(0).getVirtualResource()).thenReturn(virtualResources); - when(virtualResources.get(0).getVirtualResourceType()).thenReturn(VirtualResource.VirtualResourceType.Vport); - when(virtualResources.get(0).getParentVirtualResourceEntityId()).thenReturn(virtualResourceEntityId); - when(virtualResourceEntityId.getValue()).thenReturn(new String("11111111-1111-1111-1111-111111111111")); - when(virtualNodes.get(0).getNodeId()).thenReturn(new VirtualNodeId("11111111-1111-1111-1111-111111111111")); - when(virtualNodes.get(0).getNodeType()).thenReturn(VirtualNode.NodeType.Vrouter); + VirtualNode sourceVirtualNode = mock(VirtualNode.class); + PowerMockito.when(ActionResolverUtils.getSourceVirtualRouterOfFlow(virtualNodes, flow, nodes, intentVnMappingResults)).thenReturn(sourceVirtualNode); + VirtualNode destinationVirtualNode = mock(VirtualNode.class); + PowerMockito.when(ActionResolverUtils.getDestinationVirtualRouterOfFlow(virtualNodes, flow, nodes, intentVnMappingResults)).thenReturn(destinationVirtualNode); + when(user.getUserId()).thenReturn(userId); + VNComputationUnit vnComputationUnit = vnComputationUnits.get(userId); + //List virtualPath = new ArrayList(){{ add(mock(VirtualPath.class));}}; + VirtualPath virtualPath = mock(VirtualPath.class); + VirtualNodeId vnodeIds = mock(VirtualNodeId.class); + VirtualNodeId vnodeIdd = mock(VirtualNodeId.class); + when(sourceVirtualNode.getNodeId()).thenReturn(vnodeIds); + when(destinationVirtualNode.getNodeId()).thenReturn(vnodeIdd); + when(vnComputationUnit.computePath(vnodeIds, vnodeIdd)).thenReturn(virtualPath); + List virtualLinks = new ArrayList(){{add(mock(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.virtual.network.rev151010.virtual.path.instance.VirtualLink.class));}}; + when(virtualPath.getVirtualLink()).thenReturn(virtualLinks); + VirtualPaths virtualPaths = mock(VirtualPaths.class); + List virtualPathList = new ArrayList(); + when(virtualNetwork.getVirtualPaths()).thenReturn(virtualPaths); + when(virtualPaths.getVirtualPath()).thenReturn(virtualPathList); + when(virtualPath.getPathId()).thenReturn(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.engine.common.rev151010.VirtualPathId("11111111-1111-1111-1111-111111111111")); + when(operation.getOperationId()).thenReturn(new OperationId("11111111-1111-1111-1111-111111111111")); actionResolverTest.resolveActions(user,operation,flow,virtualNetwork, userIntentVnMapping); - - - }*/ + } @org.junit.Test public void testResolveActionsGoChain() throws Exception { - //ResolveActions() - when(operation.getAction()).thenReturn(actions); - when(actions.get(0).getActionName()).thenReturn(new ActionName("go-through")); - when(actions.get(0).getParameterValues()).thenReturn(parametervalues); - when(parametervalues.getStringValue()).thenReturn(stringValue2); - - //resolveGoThroughAction() + Node nodex = mock(Node.class); + Action goThroughAction = mock(Action.class); + method = class1.getDeclaredMethod("resolveGoThroughChainGroupAction",new Class[]{ + User.class, + Operation.class, + Flow.class, + Action.class, + Node.class, + VirtualNetwork.class, + UserIntentVnMapping.class + }); + method.setAccessible(true); + /*ParameterValues parameterValue = mock(ParameterValues.class); + List parameterValues = new ArrayList(); + StringValue stringValue = mock(StringValue.class); + parameterValues.add(stringValue); + when(goThroughAction.getParameterValues()).thenReturn(parameterValue); + when(parameterValue.getStringValue()).thenReturn(parameterValues); + List nodes = new ArrayList(); + + nodes.add(nodex); when(user.getObjects()).thenReturn(objects); - when(objects.getNode()).thenReturn(nodes3); - when(stringValue2.get(0).getValue()).thenReturn(new String("11111111-1111-1111-1111-111111111111")); - when(nodes3.get(0).getNodeId()).thenReturn(new NodeId("11111111-1111-1111-1111-111111111111")); + when(objects.getNode()).thenReturn(nodes); + when(stringValue.getValue()).thenReturn(new String("11111111-1111-1111-1111-111111111111")); + //PowerMockito.mockStatic(IntentResolverUtils.class); + //PowerMockito.when(IntentResolverUtils.getNode(any(List.class), any(NodeId.class))).thenReturn(nodex); + when(nodex.getNodeId()).thenReturn(new NodeId("11111111-1111-1111-1111-111111111111")); + when(nodex.getNodeType()).thenReturn(new NodeType("chain-group"));*/ - //chaingroup - when(nodes3.get(0).getNodeType()).thenReturn(new NodeType("chain-group")); - //resolveGoThroughChainGroupAction() when(user.getObjects()).thenReturn(objects2); when(objects2.getNode()).thenReturn(nodes3); when(virtualNetwork.getVirtualNodes()).thenReturn(virtualNode); @@ -380,105 +363,128 @@ public class ActionResolverTest extends TestCase { when(virtualPath.getVirtualPath()).thenReturn(virtualPaths); when(userIntentVnMapping.getIntentVnMappingResult()).thenReturn(intentVnMappingResults); - //when(nodes3.get(0).getSubNode()).thenReturn(new ArrayList()); - when(nodes3.get(0).getSubNode()).thenReturn(subNodes); - when(subNodes.get(0).getNodeId()).thenReturn(new NodeId("11111111-1111-1111-1111-111111111111")); - when(nodes3.get(0).getNodeId()).thenReturn(new NodeId("11111111-1111-1111-1111-111111111111")); - when(nodes3.get(0).getProperty()).thenReturn(properties2); - when(properties2.get(0).getPropertyName()).thenReturn(new PropertyName("operating-mode")); - when(properties2.get(0).getPropertyValues()).thenReturn(propertyValues); - when(propertyValues.getStringValue()).thenReturn(stringValue); - when(stringValue.get(0).getValue()).thenReturn(new String("layer1")); - when(nodes3.get(0).getSubNode()).thenReturn(subNodes); - when(subNodes.get(0).getNodeId()).thenReturn(new NodeId("11111111-1111-1111-1111-111111111111")); - when(nodes3.get(0).getNodeId()).thenReturn(new NodeId("11111111-1111-1111-1111-111111111111")); - when(nodes3.get(0).getProperty()).thenReturn(properties2); - when(properties2.get(0).getPropertyName()).thenReturn(new PropertyName("operating-mode")); - when(properties2.get(0).getPropertyValues()).thenReturn(propertyValues); - when(propertyValues.getStringValue()).thenReturn(stringValue); - when(stringValue.get(0).getValue()).thenReturn(new String("layer3")); - when(nodes3.get(0).getNodeId()).thenReturn(new NodeId("11111111-1111-1111-1111-111111111111")); - when(intentVnMappingResults.get(0).getIntentId()).thenReturn(new IntentId("11111111-1111-1111-1111-111111111111")); - - //getSourceVirtualRouterOfFlow() - when(flow.getMatchItem()).thenReturn(matchItem);//matchItem - when(matchItem.get(0).getMatchItemName()).thenReturn(new MatchItemName("src-ip")); - when(matchItem.get(0).getMatchItemValue()).thenReturn(matchItemValue);//matchItemValue - when(matchItemValue.getStringValue()).thenReturn(new String("src-ip")); - when(nodes.get(0).getNodeType()).thenReturn(new NodeType("l2-group")); - when(nodes.get(0).getProperty()).thenReturn(properties2); - when(properties2.get(0).getPropertyName()).thenReturn(new PropertyName("ip-prefix")); - when(properties2.get(0).getPropertyValues()).thenReturn(propertyValues); - when(propertyValues.getStringValue()).thenReturn(stringValue); - when(stringValue.get(0).getValue()).thenReturn(new String("src-ip")); - when(nodes.get(0).getNodeId()).thenReturn(nodeId); - when(nodeId.getValue()).thenReturn(new String("11111111-1111-1111-1111-111111111111")); - when(intentVnMappingResults.get(0).getIntentId()).thenReturn(new IntentId("11111111-1111-1111-1111-111111111111")); - when(intentVnMappingResults.get(0).getVirtualResource()).thenReturn(virtualResources); - when(virtualResources.get(0).getVirtualResourceType()).thenReturn(VirtualResource.VirtualResourceType.Vport); - when(virtualResources.get(0).getParentVirtualResourceEntityId()).thenReturn(virtualResourceEntityId); - when(virtualResourceEntityId.getValue()).thenReturn(new String("11111111-1111-1111-1111-111111111111")); - when(virtualNodes.get(0).getNodeId()).thenReturn(new VirtualNodeId("11111111-1111-1111-1111-111111111111")); - when(virtualNodes.get(0).getNodeType()).thenReturn(VirtualNode.NodeType.Vrouter); - - //getDestinationVirtualRouterOfFlow() - when(flow.getMatchItem()).thenReturn(matchItem);//matchItem - when(matchItem.get(0).getMatchItemName()).thenReturn(new MatchItemName("dst-ip")); - when(matchItem.get(0).getMatchItemValue()).thenReturn(matchItemValue);//matchItemValue - when(matchItemValue.getStringValue()).thenReturn(new String("dst-ip")); - when(nodes.get(0).getNodeType()).thenReturn(new NodeType("l2-group")); - when(nodes.get(0).getProperty()).thenReturn(properties2); - when(properties2.get(0).getPropertyName()).thenReturn(new PropertyName("ip-prefix")); - when(properties2.get(0).getPropertyValues()).thenReturn(propertyValues); - when(propertyValues.getStringValue()).thenReturn(stringValue); - when(stringValue.get(0).getValue()).thenReturn(new String("src-ip")); - when(nodes.get(0).getNodeId()).thenReturn(nodeId); - when(nodeId.getValue()).thenReturn(new String("11111111-1111-1111-1111-111111111111")); - when(intentVnMappingResults.get(0).getIntentId()).thenReturn(new IntentId("11111111-1111-1111-1111-111111111111")); - when(intentVnMappingResults.get(0).getVirtualResource()).thenReturn(virtualResources); - when(virtualResources.get(0).getVirtualResourceType()).thenReturn(VirtualResource.VirtualResourceType.Vport); - when(virtualResources.get(0).getParentVirtualResourceEntityId()).thenReturn(virtualResourceEntityId); - when(virtualResourceEntityId.getValue()).thenReturn(new String("11111111-1111-1111-1111-111111111111")); - when(virtualNodes.get(0).getNodeId()).thenReturn(new VirtualNodeId("11111111-1111-1111-1111-111111111111")); - when(virtualNodes.get(0).getNodeType()).thenReturn(VirtualNode.NodeType.Vrouter); + when(nodex.getSubNode()).thenReturn(new ArrayList()); + PowerMockito.mockStatic(IntentResolverUtils.class); + PowerMockito.when(IntentResolverUtils.checkAllLayer2OperatingMode(any(List.class), any(List.class))).thenReturn(false); + when(nodex.getSubNode()).thenReturn(new ArrayList()); + PowerMockito.when(IntentResolverUtils.checkAllLayer3OperatingMode(any(List.class), any(List.class))).thenReturn(true); + IntentVnMappingResult intentVnMappingResult = mock(IntentVnMappingResult.class); + when(nodex.getNodeId()).thenReturn(new NodeId("11111111-1111-1111-1111-111111111111")); + PowerMockito.when(IntentResolverUtils.getIntentVnMappingResult(any(List.class), any(IntentId.class))).thenReturn(intentVnMappingResult); + VirtualNode sourceVirtualNode = mock(VirtualNode.class); + PowerMockito.mockStatic(ActionResolverUtils.class); + PowerMockito.when(ActionResolverUtils.getSourceVirtualRouterOfFlow(virtualNodes, flow, nodes3, intentVnMappingResults)).thenReturn(sourceVirtualNode); + VirtualNode destinationVirtualNode = mock(VirtualNode.class); + PowerMockito.when(ActionResolverUtils.getDestinationVirtualRouterOfFlow(virtualNodes, flow, nodes3, intentVnMappingResults)).thenReturn(destinationVirtualNode); + List virtualResources1 = new ArrayList(){{add(mock(VirtualResource.class));}}; + when(intentVnMappingResult.getVirtualResource()).thenReturn(new ArrayList()); + PowerMockito.when(ActionResolverUtils.sortVirtualResources(any(List.class))).thenReturn(virtualResources1); + when(virtualResources1.get(0).getParentVirtualResourceEntityId()).thenReturn(new VirtualResourceEntityId("11111111-1111-1111-1111-111111111111")); + VirtualNode virtualNode = mock(VirtualNode.class); + PowerMockito.mockStatic(IntentResolverUtils.class); + PowerMockito.when(IntentResolverUtils.getVirtualNode(any(List.class), any(VirtualNodeId.class))).thenReturn(virtualNode); + when(virtualResources1.get(0).getParentVirtualResourceEntityId()).thenReturn(new VirtualResourceEntityId("11111111-1111-1111-1111-111111111111")); + VirtualNode virtualNode1 = mock(VirtualNode.class); + PowerMockito.when(IntentResolverUtils.getVirtualNode(any(List.class), any(VirtualNodeId.class))).thenReturn(virtualNode1); + VirtualLink virtualLink = mock(VirtualLink.class); + when(sourceVirtualNode.getNodeId()).thenReturn(mock(VirtualNodeId.class)); + when(virtualNode.getNodeId()).thenReturn(mock(VirtualNodeId.class)); + PowerMockito.when(IntentResolverUtils.getVirtualLink(any(List.class), any(VirtualNodeId.class), any(VirtualNodeId.class))).thenReturn(virtualLink); + when(virtualNode.getNodeId()).thenReturn(mock(VirtualNodeId.class)); + when(sourceVirtualNode.getNodeId()).thenReturn(mock(VirtualNodeId.class)); + when(virtualNode.getNodeId()).thenReturn(mock(VirtualNodeId.class)); + when(sourceVirtualNode.getNodeId()).thenReturn(mock(VirtualNodeId.class)); + when(virtualLink.getLinkId()).thenReturn(mock(VirtualLinkId.class)); + when(virtualNode1.getNodeId()).thenReturn(mock(VirtualNodeId.class)); + when(destinationVirtualNode.getNodeId()).thenReturn(mock(VirtualNodeId.class)); + when(destinationVirtualNode.getNodeId()).thenReturn(mock(VirtualNodeId.class)); + when(virtualNode1.getNodeId()).thenReturn(mock(VirtualNodeId.class)); + when(virtualNode1.getNodeId()).thenReturn(mock(VirtualNodeId.class)); + when(destinationVirtualNode.getNodeId()).thenReturn(mock(VirtualNodeId.class)); + when(virtualLink.getLinkId()).thenReturn(mock(VirtualLinkId.class)); + when(operation.getOperationId()).thenReturn(new OperationId("11111111-1111-1111-1111-111111111111")); + method.invoke(actionResolverTest,user,operation,flow,goThroughAction,nodex,virtualNetwork, userIntentVnMapping); + } + @org.junit.Test + public void testResolveActionsGoNormal() throws Exception { + //ResolveActions() + field = class1.getDeclaredField("vnComputationUnits"); + Map vnComputationUnits = new HashMap(); + VNComputationUnit vnComputationUnit = mock(VNComputationUnit.class); + vnComputationUnits.put(userId,vnComputationUnit); + field.setAccessible(true); + field.set(actionResolverTest,vnComputationUnits); + Node nodex = mock(Node.class); + Action goThroughAction = mock(Action.class); + method = class1.getDeclaredMethod("resolveGoThroughNormalGroupAction",new Class[]{ + User.class, + Operation.class, + Flow.class, + Action.class, + VirtualNetwork.class, + UserIntentVnMapping.class + }); + method.setAccessible(true); + IntentVnMappingResult intentVnMappingResult = mock(IntentVnMappingResult.class); + when(user.getObjects()).thenReturn(objects2); + when(objects2.getNode()).thenReturn(nodes3); + when(goThroughAction.getParameterValues()).thenReturn(parametervalues); + when(parametervalues.getStringValue()).thenReturn(stringValue2); + when(stringValue2.get(0).getValue()).thenReturn(new String("11111111-1111-1111-1111-111111111111")); + PowerMockito.mockStatic(IntentResolverUtils.class); + PowerMockito.when(IntentResolverUtils.getNode(any(List.class), any(NodeId.class))).thenReturn(nodex); + when(virtualNetwork.getVirtualNodes()).thenReturn(virtualNode); + when(virtualNode.getVirtualNode()).thenReturn(virtualNodes); + when(userIntentVnMapping.getIntentVnMappingResult()).thenReturn(intentVnMappingResults); + PowerMockito.mockStatic(ActionResolverUtils.class); + PowerMockito.when(ActionResolverUtils.sortParameterValues(any(List.class))).thenReturn(stringValue2); + when(stringValue2.get(0).getValue()).thenReturn(new String("11111111-1111-1111-1111-111111111111")); when(intentVnMappingResults.get(0).getVirtualResource()).thenReturn(virtualResources); + when(stringValue.get(0).getValue()).thenReturn(new String("11111111-1111-1111-1111-111111111111")); + PowerMockito.mockStatic(IntentResolverUtils.class); + PowerMockito.when(IntentResolverUtils.getIntentVnMappingResult(any(List.class), any(IntentId.class))).thenReturn(intentVnMappingResult); + when(intentVnMappingResult.getVirtualResource()).thenReturn(virtualResources); + when(virtualResources.get(0).getVirtualResourceType()).thenReturn(VirtualResource.VirtualResourceType.Vnode); + when(virtualResources.get(0).getVirtualResourceEntityId()).thenReturn(virtualResourceEntityId); + when(virtualResourceEntityId.getValue()).thenReturn("11111111-1111-1111-1111-111111111111"); - when(virtualResources.get(0).getParentVirtualResourceEntityId()).thenReturn(virtualResourceEntityId); - when(virtualResourceEntityId.getValue()).thenReturn(new String("11111111-1111-1111-1111-111111111111")); - when(virtualNodes.get(0).getNodeId()).thenReturn(new VirtualNodeId("11111111-1111-1111-1111-111111111111")); - - when(virtualResources.get(0).getParentVirtualResourceEntityId()).thenReturn(virtualResourceEntityId); - when(virtualResourceEntityId.getValue()).thenReturn(new String("11111111-1111-1111-1111-111111111112")); - when(virtualNodes.get(0).getNodeId()).thenReturn(new VirtualNodeId("11111111-1111-1111-1111-111111111112")); - - when(virtualNodes.get(0).getNodeId()).thenReturn(new VirtualNodeId("11111111-1111-1111-1111-111111111111")); - when(virtualNodes.get(0).getNodeId()).thenReturn(new VirtualNodeId("11111111-1111-1111-1111-111111111112")); - when(virtualLinks.get(0).getSrcNodeId()).thenReturn(new VirtualNodeId("11111111-1111-1111-1111-111111113111")); - when(virtualLinks.get(0).getDestNodeId()).thenReturn(new VirtualNodeId("11111111-1111-1111-1111-111111131112")); - when(virtualNodes.get(0).getVirtualPort()).thenReturn(virtualPorts1); - when(virtualNodes.get(0).getVirtualPort()).thenReturn(virtualPorts2); - when(virtualNodes.get(0).getNodeId()).thenReturn(new VirtualNodeId("11111111-1111-1111-1111-111111111111")); - when(virtualNodes.get(0).getNodeId()).thenReturn(new VirtualNodeId("11111111-1111-1111-1111-111111111112")); - when(virtualNodes.get(0).getNodeId()).thenReturn(new VirtualNodeId("11111111-1111-1111-1111-111111111112")); - when(virtualNodes.get(0).getNodeId()).thenReturn(new VirtualNodeId("11111111-1111-1111-1111-111111111111")); + PowerMockito.when(IntentResolverUtils.getVirtualNode(any(List.class), any(VirtualNodeId.class))).thenReturn(virtualNodes.get(0)); + VirtualNode sourceVirtualNode = mock(VirtualNode.class); + PowerMockito.mockStatic(ActionResolverUtils.class); + PowerMockito.when(ActionResolverUtils.getSourceVirtualRouterOfFlow(virtualNodes, flow, nodes3, intentVnMappingResults)).thenReturn(sourceVirtualNode); + VirtualNode destinationVirtualNode = mock(VirtualNode.class); + PowerMockito.when(ActionResolverUtils.getDestinationVirtualRouterOfFlow(virtualNodes, flow, nodes3, intentVnMappingResults)).thenReturn(destinationVirtualNode); + when(user.getUserId()).thenReturn(userId); + VirtualPath virtualPath1 = mock(VirtualPath.class); - when(operation.getOperationId()).thenReturn(new OperationId("11111111-1111-1111-1111-111111131112")); + VirtualNodeId virtualNodeId1 = new VirtualNodeId("11111111-1111-1111-1111-111111111111"); + VirtualNodeId virtualNodeId2 = new VirtualNodeId("11111111-1111-1111-1111-111111111112"); + when(sourceVirtualNode.getNodeId()).thenReturn(virtualNodeId1); + when(virtualNodes.get(0).getNodeId()).thenReturn(virtualNodeId2); + when(sourceVirtualNode.getNodeId()).thenReturn(virtualNodeId1); + when(virtualNodes.get(0).getNodeId()).thenReturn(virtualNodeId2); + when(vnComputationUnit.computePath(virtualNodeId1,virtualNodeId2)).thenReturn(virtualPath1); + when(destinationVirtualNode.getNodeId()).thenReturn(virtualNodeId1); + when(virtualNodes.get(0).getNodeId()).thenReturn(virtualNodeId2); + when(virtualNodes.get(0).getNodeId()).thenReturn(virtualNodeId2); + when(destinationVirtualNode.getNodeId()).thenReturn(virtualNodeId1); + when(vnComputationUnit.computePath(virtualNodeId2,virtualNodeId1)).thenReturn(virtualPath1); + VirtualPaths virtualPaths = mock(VirtualPaths.class); + List virtualPathList = new ArrayList(); + when(virtualNetwork.getVirtualPaths()).thenReturn(virtualPaths); + when(virtualPaths.getVirtualPath()).thenReturn(virtualPathList); - actionResolverTest.resolveActions(user,operation,flow,virtualNetwork, userIntentVnMapping); - } - @org.junit.Test - public void testResolveActionsGoNormal() throws Exception { - //ResolveActions() - when(operation.getAction()).thenReturn(actions); + //method.invoke(actionResolverTest,user,operation,flow,goThroughAction,virtualNetwork, userIntentVnMapping); + /*when(operation.getAction()).thenReturn(actions); when(actions.get(0).getActionName()).thenReturn(new ActionName("go-through")); when(actions.get(0).getParameterValues()).thenReturn(parametervalues); when(parametervalues.getStringValue()).thenReturn(stringValue2); @@ -561,7 +567,7 @@ public class ActionResolverTest extends TestCase { when(virtualNodes.get(0).getNodeType()).thenReturn(VirtualNode.NodeType.Vrouter); - //actionResolverTest.resolveActions(user,operation,flow,virtualNetwork, userIntentVnMapping); + //actionResolverTest.resolveActions(user,operation,flow,virtualNetwork, userIntentVnMapping);*/ } diff --git a/nemo-impl/src/test/java/org/opendaylight/nemo/user/vnspacemanager/languagestyle/NEMOParse/NEMOparserTokenManagerTest.java b/nemo-impl/src/test/java/org/opendaylight/nemo/user/vnspacemanager/languagestyle/NEMOParse/NEMOparserTokenManagerTest.java index 394d3a6..ee308fe 100644 --- a/nemo-impl/src/test/java/org/opendaylight/nemo/user/vnspacemanager/languagestyle/NEMOParse/NEMOparserTokenManagerTest.java +++ b/nemo-impl/src/test/java/org/opendaylight/nemo/user/vnspacemanager/languagestyle/NEMOParse/NEMOparserTokenManagerTest.java @@ -1,819 +1,819 @@ -/* - * Copyright (c) 2015 Huawei, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -/* Generated By:JavaCC: Do not edit this line. NEMOparserTokenManager.java */ -package org.opendaylight.nemo.user.vnspacemanager.languagestyle.NEMOParse; -import junit.framework.TestCase; -import org.junit.Assert; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.opendaylight.nemo.user.vnspacemanager.languagestyle.NEMOParse.NEMOparser; -import org.opendaylight.nemo.user.vnspacemanager.languagestyle.NEMOParse.NEMOparserTokenManager; -import org.opendaylight.nemo.user.vnspacemanager.languagestyle.NEMOParse.SimpleCharStream; -import org.opendaylight.nemo.user.vnspacemanager.languagestyle.NEMOParse.Token; - -import java.io.IOException; -import java.io.PrintStream; -import java.io.Reader; -import java.lang.reflect.Field; -import java.lang.reflect.Member; -import java.lang.reflect.Method; - -import static org.junit.Assert.*; -import static org.mockito.Mockito.*; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.api.support.membermodification.MemberMatcher; -import org.powermock.api.support.membermodification.MemberModifier; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; -/** - * Created by zhangmeng on 2015/12/17. - */ -@RunWith(PowerMockRunner.class) -@PrepareForTest({NEMOparserTokenManager.class,SimpleCharStream.class}) -public class NEMOparserTokenManagerTest extends TestCase { - private SimpleCharStream simpleCharStream; - private int lexState; - private NEMOparserTokenManager nemOparserTokenManager; - private Class class1; - private Field field; - @Before - public void setUp() throws Exception { - class1 = NEMOparserTokenManager.class; - field = class1.getDeclaredField("input_stream"); - field.setAccessible(true); - field.set(class1,null); - - simpleCharStream = mock(SimpleCharStream.class); - lexState = 0; - } - - @Test - public void Init_ReInit() throws Exception{ - nemOparserTokenManager = new NEMOparserTokenManager(simpleCharStream); - NEMOparserTokenManager.ReInit(null); - nemOparserTokenManager = new NEMOparserTokenManager(simpleCharStream,lexState);//curLexstate = 0 - NEMOparserTokenManager.ReInit(null, lexState); - - Assert.assertTrue(field.get(class1) == null); - } - - @Test - public void testSetDebugStream() throws Exception { - NEMOparserTokenManager.setDebugStream(null); - Field field1 = class1.getField("debugStream"); - field1.setAccessible(true); - Assert.assertTrue(field1.get(class1) == null); - } - - - @Test - public void testJjFillToken() throws Exception { - nemOparserTokenManager = new NEMOparserTokenManager(simpleCharStream); - PowerMockito.mockStatic(SimpleCharStream.class); - PowerMockito.when(SimpleCharStream.GetImage()).thenReturn("test"); - Assert.assertTrue(NEMOparserTokenManager.jjFillToken() != null); - } - - @Test - public void testGetNextToken() throws Exception { - char curChar = 40; - nemOparserTokenManager = new NEMOparserTokenManager(simpleCharStream); - Assert.assertTrue(field.get(nemOparserTokenManager) == simpleCharStream); - PowerMockito.mockStatic(SimpleCharStream.class); - PowerMockito.when(SimpleCharStream.BeginToken()).thenReturn(curChar); -// System.out.println("out :" + NEMOparserTokenManager.getNextToken()); - Assert.assertTrue(NEMOparserTokenManager.getNextToken() != null); - } - - @Test - public void testjjStartNfa_0() throws Exception{ - Method method = class1.getDeclaredMethod("jjStartNfa_0",new Class[]{int.class,long.class}); - method.setAccessible(true); - int pos = 1; - long active0 = 1L; - - Assert.assertTrue((Integer) method.invoke(class1, pos, active0) == 3); -// System.out.println("method.invoke(class1,pos,active0):" + method.invoke(class1,pos,active0)); - } - - @Test - public void testjjStopStringLiteralDfa_0() throws Exception{ - Method method = class1.getDeclaredMethod("jjStopStringLiteralDfa_0",new Class[]{ - int.class, - long.class - }); - method.setAccessible(true); -// System.out.println("testjjStopStringLiteralDfa_0" + method.invoke(class1, 0, 0)); - Assert.assertTrue((Integer) method.invoke(class1, 0, 0) == -1); -// System.out.println("testjjStopStringLiteralDfa_0" + method.invoke(class1, 0, 0x74800000000000L)); - Assert.assertTrue((Integer) method.invoke(class1, 0, 0x74800000000000L) == 205); -// System.out.println("testjjStopStringLiteralDfa_0" + method.invoke(class1, 0, 0x3000000000000L)); - Assert.assertTrue((Integer) method.invoke(class1, 0, 0x3000000000000L) == 81); - //case1 - Assert.assertTrue((Integer) method.invoke(class1, 1, 0x77800000000000L) == 205); - Assert.assertTrue((Integer) method.invoke(class1, 1, 0) == -1); - //case2 - Assert.assertTrue((Integer) method.invoke(class1, 2, 0x77800000000000L) == 205); - Assert.assertTrue((Integer) method.invoke(class1, 2, 0) == -1); - //case3 - Assert.assertTrue((Integer) method.invoke(class1, 3, 0x77800000000000L) == 205); - Assert.assertTrue((Integer) method.invoke(class1, 3, 0) == -1); - //case4 - Assert.assertTrue((Integer) method.invoke(class1, 4, 0x35000000000000L) == 205); - Assert.assertTrue((Integer) method.invoke(class1, 4, 0x42800000000000L) == 205); - Assert.assertTrue((Integer) method.invoke(class1, 4, 0) == -1); - //case5 - Assert.assertTrue((Integer) method.invoke(class1, 5, 0x25000000000000L) == 205); - Assert.assertTrue((Integer) method.invoke(class1, 5, 0x10000000000000L) == 205); - Assert.assertTrue((Integer) method.invoke(class1, 5, 0) == -1); - //case6 - Assert.assertTrue((Integer) method.invoke(class1, 6, 0x5000000000000L) == 205); - Assert.assertTrue((Integer) method.invoke(class1, 6, 0x20000000000000L) == 205); - Assert.assertTrue((Integer) method.invoke(class1, 6, 0) == -1); - //case7 - Assert.assertTrue((Integer) method.invoke(class1, 7, 0x5000000000000L) == 205); - Assert.assertTrue((Integer) method.invoke(class1, 7, 0) == -1); - //case8 - Assert.assertTrue((Integer) method.invoke(class1, 8, 0x5000000000000L) == 205); - Assert.assertTrue((Integer) method.invoke(class1, 8, 0) == -1); - //case9 - Assert.assertTrue((Integer) method.invoke(class1, 9, 0x4000000000000L) == 205); - Assert.assertTrue((Integer) method.invoke(class1, 9, 0x1000000000000L) == 205); - Assert.assertTrue((Integer) method.invoke(class1, 9, 0) == -1); - //case default - Assert.assertTrue((Integer) method.invoke(class1, 10, 0) == -1); - - } - - @Test - public void testjjStopAtPos() throws Exception{ - Method method = class1.getDeclaredMethod("jjStopAtPos",new Class[]{ - int.class, - int.class - }); - method.setAccessible(true); - - Assert.assertTrue((Integer) method.invoke(class1,1,1) == 2); - } - - @Test - public void testjjMoveStringLiteralDfa0_0() throws Exception{ - Method method = class1.getDeclaredMethod("jjMoveStringLiteralDfa0_0"); - method.setAccessible(true); - Field field = class1.getDeclaredField("curChar"); - field.setAccessible(true); - - PowerMockito.mockStatic(SimpleCharStream.class); - PowerMockito.when(SimpleCharStream.readChar()).thenReturn((char) 0); - - NEMOparserTokenManager.curChar = 33; -// System.out.println("jjMoveStringLiteralDfa0_0" + method.invoke(class1)); - Assert.assertTrue((Integer) method.invoke(class1) != 0); - NEMOparserTokenManager.curChar = 38; -// System.out.println("jjMoveStringLiteralDfa0_0" + method.invoke(class1)); - Assert.assertTrue((Integer) method.invoke(class1) != 0); - NEMOparserTokenManager.curChar = 40; -// System.out.println("jjMoveStringLiteralDfa0_0" + method.invoke(class1)); - Assert.assertTrue((Integer) method.invoke(class1) != 0); - NEMOparserTokenManager.curChar = 41; -// System.out.println("jjMoveStringLiteralDfa0_0" + method.invoke(class1)); - Assert.assertTrue((Integer) method.invoke(class1) != 0); - NEMOparserTokenManager.curChar = 42; -// System.out.println("jjMoveStringLiteralDfa0_0" + method.invoke(class1)); - Assert.assertTrue((Integer) method.invoke(class1) != 0); - NEMOparserTokenManager.curChar = 43; -// System.out.println("jjMoveStringLiteralDfa0_0" + method.invoke(class1)); - Assert.assertTrue((Integer) method.invoke(class1) != 0); - NEMOparserTokenManager.curChar = 44; -// System.out.println("jjMoveStringLiteralDfa0_0" + method.invoke(class1)); - Assert.assertTrue((Integer) method.invoke(class1) != 0); - NEMOparserTokenManager.curChar = 58; -// System.out.println("jjMoveStringLiteralDfa0_0" + method.invoke(class1)); - Assert.assertTrue((Integer) method.invoke(class1) != 0); - NEMOparserTokenManager.curChar = 59; -// System.out.println("jjMoveStringLiteralDfa0_0" + method.invoke(class1)); - Assert.assertTrue((Integer) method.invoke(class1) != 0); - NEMOparserTokenManager.curChar = 60; -// System.out.println("jjMoveStringLiteralDfa0_0" + method.invoke(class1)); - Assert.assertTrue((Integer) method.invoke(class1) != 0); - NEMOparserTokenManager.curChar = 61; -// System.out.println("jjMoveStringLiteralDfa0_0" + method.invoke(class1)); - Assert.assertTrue((Integer) method.invoke(class1) != 0); - NEMOparserTokenManager.curChar = 65; -// System.out.println("jjMoveStringLiteralDfa0_0" + method.invoke(class1)); - Assert.assertTrue((Integer) method.invoke(class1) != 0); - NEMOparserTokenManager.curChar = 66; -// System.out.println("jjMoveStringLiteralDfa0_0" + method.invoke(class1)); - Assert.assertTrue((Integer) method.invoke(class1) != 0); - NEMOparserTokenManager.curChar = 67; -// System.out.println("jjMoveStringLiteralDfa0_0" + method.invoke(class1)); - Assert.assertTrue((Integer) method.invoke(class1) != 0); - NEMOparserTokenManager.curChar = 68; -// System.out.println("jjMoveStringLiteralDfa0_0" + method.invoke(class1)); - Assert.assertTrue((Integer) method.invoke(class1) != 0); - NEMOparserTokenManager.curChar = 69; -// System.out.println("jjMoveStringLiteralDfa0_0" + method.invoke(class1)); - Assert.assertTrue((Integer) method.invoke(class1) != 0); - NEMOparserTokenManager.curChar = 70; -// System.out.println("jjMoveStringLiteralDfa0_0" + method.invoke(class1)); - Assert.assertTrue((Integer) method.invoke(class1) != 0); - NEMOparserTokenManager.curChar = 73; -// System.out.println("jjMoveStringLiteralDfa0_0" + method.invoke(class1)); - Assert.assertTrue((Integer) method.invoke(class1) != 0); - NEMOparserTokenManager.curChar = 77; -// System.out.println("jjMoveStringLiteralDfa0_0" + method.invoke(class1)); - Assert.assertTrue((Integer) method.invoke(class1) != 0); - NEMOparserTokenManager.curChar = 78; -// System.out.println("jjMoveStringLiteralDfa0_0" + method.invoke(class1)); - Assert.assertTrue((Integer) method.invoke(class1) != 0); - NEMOparserTokenManager.curChar = 79; -// System.out.println("jjMoveStringLiteralDfa0_0" + method.invoke(class1)); - Assert.assertTrue((Integer) method.invoke(class1) != 0); - NEMOparserTokenManager.curChar = 80; -// System.out.println("jjMoveStringLiteralDfa0_0" + method.invoke(class1)); - Assert.assertTrue((Integer) method.invoke(class1) != 0); - NEMOparserTokenManager.curChar = 81; -// System.out.println("jjMoveStringLiteralDfa0_0" + method.invoke(class1)); - Assert.assertTrue((Integer) method.invoke(class1) != 0); - NEMOparserTokenManager.curChar = 84; -// System.out.println("jjMoveStringLiteralDfa0_0" + method.invoke(class1)); - Assert.assertTrue((Integer) method.invoke(class1) != 0); - NEMOparserTokenManager.curChar = 85; -// System.out.println("jjMoveStringLiteralDfa0_0" + method.invoke(class1)); - Assert.assertTrue((Integer) method.invoke(class1) != 0); - NEMOparserTokenManager.curChar = 91; -// System.out.println("jjMoveStringLiteralDfa0_0" + method.invoke(class1)); - Assert.assertTrue((Integer) method.invoke(class1) != 0); - NEMOparserTokenManager.curChar = 93; -// System.out.println("jjMoveStringLiteralDfa0_0" + method.invoke(class1)); - Assert.assertTrue((Integer) method.invoke(class1) != 0); - NEMOparserTokenManager.curChar = 99; -// System.out.println("jjMoveStringLiteralDfa0_0" + method.invoke(class1)); - Assert.assertTrue((Integer) method.invoke(class1) != 0); - NEMOparserTokenManager.curChar = 102; -// System.out.println("jjMoveStringLiteralDfa0_0" + method.invoke(class1)); - Assert.assertTrue((Integer) method.invoke(class1) != 0); - NEMOparserTokenManager.curChar = 105; -// System.out.println("jjMoveStringLiteralDfa0_0" + method.invoke(class1)); - Assert.assertTrue((Integer) method.invoke(class1) != 0); - NEMOparserTokenManager.curChar = 110; -// System.out.println("jjMoveStringLiteralDfa0_0" + method.invoke(class1)); - Assert.assertTrue((Integer) method.invoke(class1) != 0); - NEMOparserTokenManager.curChar = 111; -// System.out.println("jjMoveStringLiteralDfa0_0" + method.invoke(class1)); - Assert.assertTrue((Integer) method.invoke(class1) != 0); - NEMOparserTokenManager.curChar = 114; -// System.out.println("jjMoveStringLiteralDfa0_0" + method.invoke(class1)); - Assert.assertTrue((Integer) method.invoke(class1) != 0); - NEMOparserTokenManager.curChar = 115; -// System.out.println("jjMoveStringLiteralDfa0_0" + method.invoke(class1)); - Assert.assertTrue((Integer) method.invoke(class1) != 0); - NEMOparserTokenManager.curChar = 124; -// System.out.println("jjMoveStringLiteralDfa0_0" + method.invoke(class1)); - Assert.assertTrue((Integer) method.invoke(class1) != 0); - NEMOparserTokenManager.curChar = 1; -// System.out.println("jjMoveStringLiteralDfa0_0" + method.invoke(class1)); - Assert.assertTrue((Integer) method.invoke(class1) != 0); - } - - @Test - public void testjjMoveStringLiteralDfa1_0() throws Exception{ - Method method = class1.getDeclaredMethod("jjMoveStringLiteralDfa1_0",new Class[]{long.class}); - method.setAccessible(true); - - PowerMockito.mockStatic(SimpleCharStream.class); - PowerMockito.when(SimpleCharStream.readChar()) - .thenReturn((char) 0) - .thenReturn((char) 38) - .thenReturn((char) 61) - .thenReturn((char) 61) - .thenReturn((char) 61) - .thenReturn((char) 69) - .thenReturn((char) 77) - .thenReturn((char) 80) - .thenReturn((char) 82) - .thenReturn((char) 97) - .thenReturn((char) 99) - .thenReturn((char) 101) - .thenReturn((char) 108) - .thenReturn((char) 110) - .thenReturn((char) 111) - .thenReturn((char) 112) - .thenReturn((char) 114) - .thenReturn((char) 116) - .thenReturn((char) 117) - .thenReturn((char) 121) - .thenReturn((char) 124); - - //case default - Assert.assertTrue((Integer) method.invoke(class1, 1L) == 2); - Assert.assertTrue(NEMOparserTokenManager.curChar == 0); - //case 38 and so on -// System.out.println("0x8000L" + method.invoke(class1, 0x1000L)); - Assert.assertTrue((Integer) method.invoke(class1, 0x1000L) == 2); - Assert.assertTrue(NEMOparserTokenManager.curChar == 38); -// System.out.println("0x8000L" + method.invoke(class1, 0x8000L)); - Assert.assertTrue((Integer) method.invoke(class1, 0x8000L) == 2); - Assert.assertTrue(NEMOparserTokenManager.curChar == 61); -// System.out.println("0x8000L" + method.invoke(class1,0x40000L)); - Assert.assertTrue((Integer) method.invoke(class1, 0x40000L) == 2); - Assert.assertTrue(NEMOparserTokenManager.curChar == 61); -// System.out.println("0x8000L" + method.invoke(class1,0x80000L)); - Assert.assertTrue((Integer) method.invoke(class1, 0x80000L) == 2); - Assert.assertTrue(NEMOparserTokenManager.curChar == 61); -// System.out.println("0x8000L" + method.invoke(class1,0L)); - Assert.assertTrue((Integer) method.invoke(class1, 0L) == 2); - Assert.assertTrue(NEMOparserTokenManager.curChar == 69); - Assert.assertTrue((Integer) method.invoke(class1, 0L) == 2); - Assert.assertTrue(NEMOparserTokenManager.curChar == 77); - Assert.assertTrue((Integer) method.invoke(class1, 0L) == 2); - Assert.assertTrue(NEMOparserTokenManager.curChar == 80); - Assert.assertTrue((Integer) method.invoke(class1, 0L) == 2); - Assert.assertTrue(NEMOparserTokenManager.curChar == 82); - Assert.assertTrue((Integer) method.invoke(class1, 0L) == 2); - Assert.assertTrue(NEMOparserTokenManager.curChar == 97); - Assert.assertTrue((Integer) method.invoke(class1, 0L) == 2); - Assert.assertTrue(NEMOparserTokenManager.curChar == 99); - Assert.assertTrue((Integer) method.invoke(class1, 0L) == 2); - Assert.assertTrue(NEMOparserTokenManager.curChar == 101); - Assert.assertTrue((Integer) method.invoke(class1, 0L) == 2); - Assert.assertTrue(NEMOparserTokenManager.curChar == 108); - Assert.assertTrue((Integer) method.invoke(class1, 0L) == 2); - Assert.assertTrue(NEMOparserTokenManager.curChar == 110); - Assert.assertTrue((Integer) method.invoke(class1, 0L) == 2); - Assert.assertTrue(NEMOparserTokenManager.curChar == 111); - Assert.assertTrue((Integer) method.invoke(class1, 0L) == 2); - Assert.assertTrue(NEMOparserTokenManager.curChar == 112); - Assert.assertTrue((Integer) method.invoke(class1, 0L) == 2); - Assert.assertTrue(NEMOparserTokenManager.curChar == 114); - Assert.assertTrue((Integer) method.invoke(class1, 0L) == 2); - Assert.assertTrue(NEMOparserTokenManager.curChar == 116); - Assert.assertTrue((Integer) method.invoke(class1, 0L) == 2); - Assert.assertTrue(NEMOparserTokenManager.curChar == 117); - Assert.assertTrue((Integer) method.invoke(class1, 0L) == 2); - Assert.assertTrue(NEMOparserTokenManager.curChar == 121); - Assert.assertTrue((Integer) method.invoke(class1, 0L) == 2); - Assert.assertTrue(NEMOparserTokenManager.curChar == 124); - } - - @Test - public void testjjMoveStringLiteralDfa2_0() throws Exception{ - Method method = class1.getDeclaredMethod("jjMoveStringLiteralDfa2_0",new Class[]{ - long.class, - long.class - }); - method.setAccessible(true); - - PowerMockito.mockStatic(SimpleCharStream.class); - PowerMockito.when(SimpleCharStream.readChar()) - .thenReturn((char) 0) - .thenReturn((char) 68) - .thenReturn((char) 69) - .thenReturn((char) 76) - .thenReturn((char) 80) - .thenReturn((char) 97) - .thenReturn((char) 100) - .thenReturn((char) 101) - .thenReturn((char) 103) - .thenReturn((char) 105) - .thenReturn((char) 110) - .thenReturn((char) 111) - .thenReturn((char) 112) - .thenReturn((char) 114) - .thenReturn((char) 116); - - //case default -// System.out.println("0x8000L" + method.invoke(class1, 1L, 1L)); - Assert.assertTrue((Integer)method.invoke(class1,1L,1L) == 3); - Assert.assertTrue(NEMOparserTokenManager.curChar == 0); - //case others - Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 3); - Assert.assertTrue(NEMOparserTokenManager.curChar == 68); - Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 3); - Assert.assertTrue(NEMOparserTokenManager.curChar == 69); - Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 3); - Assert.assertTrue(NEMOparserTokenManager.curChar == 76); - Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 3); - Assert.assertTrue(NEMOparserTokenManager.curChar == 80); - Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 3); - Assert.assertTrue(NEMOparserTokenManager.curChar == 97); - Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 3); - Assert.assertTrue(NEMOparserTokenManager.curChar == 100); - Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 3); - Assert.assertTrue(NEMOparserTokenManager.curChar == 101); - Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 3); - Assert.assertTrue(NEMOparserTokenManager.curChar == 103); - Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 3); - Assert.assertTrue(NEMOparserTokenManager.curChar == 105); - Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 3); - Assert.assertTrue(NEMOparserTokenManager.curChar == 110); - Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 3); - Assert.assertTrue(NEMOparserTokenManager.curChar == 111); - Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 3); - Assert.assertTrue(NEMOparserTokenManager.curChar == 112); - Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 3); - Assert.assertTrue(NEMOparserTokenManager.curChar == 114); - Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 3); - Assert.assertTrue(NEMOparserTokenManager.curChar == 116); - - } - - @Test - public void testjjMoveStringLiteralDfa3_0() throws Exception{ - Method method = class1.getDeclaredMethod("jjMoveStringLiteralDfa3_0",new Class[]{ - long.class, - long.class - }); - method.setAccessible(true); - - PowerMockito.mockStatic(SimpleCharStream.class); - PowerMockito.when(SimpleCharStream.readChar()) - .thenReturn((char) 0) - .thenReturn((char) 65) - .thenReturn((char) 69) - .thenReturn((char) 79) - .thenReturn((char) 99) - .thenReturn((char) 100) - .thenReturn((char) 101) - .thenReturn((char) 103) - .thenReturn((char) 105) - .thenReturn((char) 109) - .thenReturn((char) 110) - .thenReturn((char) 111) - .thenReturn((char) 112) - .thenReturn((char) 114) - .thenReturn((char) 116) - .thenReturn((char) 119); - - //case default - Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 4); - Assert.assertTrue(NEMOparserTokenManager.curChar == 0); - //case others - Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 4); - Assert.assertTrue(NEMOparserTokenManager.curChar == 65); - Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 4); - Assert.assertTrue(NEMOparserTokenManager.curChar == 69); - Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 4); - Assert.assertTrue(NEMOparserTokenManager.curChar == 79); - Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 4); - Assert.assertTrue(NEMOparserTokenManager.curChar == 99); - Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 4); - Assert.assertTrue(NEMOparserTokenManager.curChar == 100); - Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 4); - Assert.assertTrue(NEMOparserTokenManager.curChar == 101); - Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 4); - Assert.assertTrue(NEMOparserTokenManager.curChar == 103); - Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 4); - Assert.assertTrue(NEMOparserTokenManager.curChar == 105); - Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 4); - Assert.assertTrue(NEMOparserTokenManager.curChar == 109); - Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 4); - Assert.assertTrue(NEMOparserTokenManager.curChar == 110); - Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 4); - Assert.assertTrue(NEMOparserTokenManager.curChar == 111); - Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 4); - Assert.assertTrue(NEMOparserTokenManager.curChar == 112); - Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 4); - Assert.assertTrue(NEMOparserTokenManager.curChar == 114); - Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 4); - Assert.assertTrue(NEMOparserTokenManager.curChar == 116); - Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 4); - Assert.assertTrue(NEMOparserTokenManager.curChar == 119); - - } - - @Test - public void testjjMoveStringLiteralDfa4_0() throws Exception{ - Method method = class1.getDeclaredMethod("jjMoveStringLiteralDfa4_0",new Class[]{ - long.class, - long.class - }); - method.setAccessible(true); - - PowerMockito.mockStatic(SimpleCharStream.class); - PowerMockito.when(SimpleCharStream.readChar()) - .thenReturn((char) 0) - .thenReturn((char) 77) - .thenReturn((char) 82) - .thenReturn((char) 84) - .thenReturn((char) 97) - .thenReturn((char) 101) -// .thenReturn((char) 101) - .thenReturn((char) 103) - .thenReturn((char) 104) -// .thenReturn((char) 104) - .thenReturn((char) 105) -// .thenReturn((char) 110) - .thenReturn((char) 110) - .thenReturn((char) 111) - .thenReturn((char) 114) -// .thenReturn((char) 115) -// .thenReturn((char) 115) - .thenReturn((char) 115) - .thenReturn((char) 121); - - //case default: - Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 5); - Assert.assertTrue(NEMOparserTokenManager.curChar == 0); - //case others - Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 5); - Assert.assertTrue(NEMOparserTokenManager.curChar == 77); - Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 5); - Assert.assertTrue(NEMOparserTokenManager.curChar == 82); - Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 5); - Assert.assertTrue(NEMOparserTokenManager.curChar == 84); - Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 5); - Assert.assertTrue(NEMOparserTokenManager.curChar == 97); -// Assert.assertTrue((Integer) method.invoke(class1, 0x40000000000000L, 0x40000000000000L) == 5); -// System.out.println("0x40000000000000L" + method.invoke(class1, 0x40000000000000L, 0x40000000000000L)); -// Assert.assertTrue(NEMOparserTokenManager.curChar == 101); - Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 5); - Assert.assertTrue(NEMOparserTokenManager.curChar == 101); - Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 5); - Assert.assertTrue(NEMOparserTokenManager.curChar == 103); -// System.out.println("0x40000000000000L" + method.invoke(class1, 0x1000000000L, 0x1000000000L)); -// Assert.assertTrue(NEMOparserTokenManager.curChar == 104); - Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 5); - Assert.assertTrue(NEMOparserTokenManager.curChar == 104); - Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 5); - Assert.assertTrue(NEMOparserTokenManager.curChar == 105); -// System.out.println("0x40000000000000L" + method.invoke(class1, 0x200000000000L, 0x200000000000L)); -// Assert.assertTrue(NEMOparserTokenManager.curChar == 110); - Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 5); - Assert.assertTrue(NEMOparserTokenManager.curChar == 110); - Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 5); - Assert.assertTrue(NEMOparserTokenManager.curChar == 111); - Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 5); - Assert.assertTrue(NEMOparserTokenManager.curChar == 114); - Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 5); - Assert.assertTrue(NEMOparserTokenManager.curChar == 115); - Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 5); - Assert.assertTrue(NEMOparserTokenManager.curChar == 121); - } - - @Test - public void testjjMoveStringLiteralDfa5_0() throws Exception{ - Method method = class1.getDeclaredMethod("jjMoveStringLiteralDfa5_0",new Class[]{ - long.class, - long.class - }); - method.setAccessible(true); - - PowerMockito.mockStatic(SimpleCharStream.class); - PowerMockito.when(SimpleCharStream.readChar()) - .thenReturn((char) 0) - .thenReturn((char) 69) - .thenReturn((char) 69) - .thenReturn((char) 69) - .thenReturn((char) 84) - .thenReturn((char) 97) - .thenReturn((char) 99) - .thenReturn((char) 100) - .thenReturn((char) 101) - .thenReturn((char) 103) - .thenReturn((char) 105) - .thenReturn((char) 110) - .thenReturn((char) 111) - .thenReturn((char) 114) - .thenReturn((char) 116) - .thenReturn((char) 116); - - - //case default: - Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 6); - Assert.assertTrue(NEMOparserTokenManager.curChar == 0); - //case others - Assert.assertTrue((Integer) method.invoke(class1, 0x2000000L, 0x2000000L) == 6); - Assert.assertTrue(NEMOparserTokenManager.curChar == 69); - Assert.assertTrue((Integer) method.invoke(class1, 0x10000000L, 0x10000000L) == 6); - Assert.assertTrue(NEMOparserTokenManager.curChar == 69); - Assert.assertTrue((Integer) method.invoke(class1, 0x8000000L, 0x8000000L) == 6); - Assert.assertTrue(NEMOparserTokenManager.curChar == 69); - Assert.assertTrue((Integer) method.invoke(class1, 0x4000000L, 0x4000000L) == 6); - Assert.assertTrue(NEMOparserTokenManager.curChar == 84); - Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 6); - Assert.assertTrue(NEMOparserTokenManager.curChar == 97); - Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 6); - Assert.assertTrue(NEMOparserTokenManager.curChar == 99); - Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 6); - Assert.assertTrue(NEMOparserTokenManager.curChar == 100); - Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 6); - Assert.assertTrue(NEMOparserTokenManager.curChar == 101); - Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 6); - Assert.assertTrue(NEMOparserTokenManager.curChar == 103); - Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 6); - Assert.assertTrue(NEMOparserTokenManager.curChar == 105); - Assert.assertTrue((Integer) method.invoke(class1, 0x10000000000L, 0x10000000000L) == 6); - Assert.assertTrue(NEMOparserTokenManager.curChar == 110); - Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 6); - Assert.assertTrue(NEMOparserTokenManager.curChar == 111); - Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 6); - Assert.assertTrue(NEMOparserTokenManager.curChar == 114); - Assert.assertTrue((Integer) method.invoke(class1, 0x4000000000L, 0x4000000000L) == 6); - Assert.assertTrue(NEMOparserTokenManager.curChar == 116); - Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 6); - Assert.assertTrue(NEMOparserTokenManager.curChar == 116); - } - - @Test - public void testjjMoveStringLiteralDfa6_0() throws Exception{ - Method method = class1.getDeclaredMethod("jjMoveStringLiteralDfa6_0",new Class[]{ - long.class, - long.class - }); - method.setAccessible(true); - - PowerMockito.mockStatic(SimpleCharStream.class); - PowerMockito.when(SimpleCharStream.readChar()) - .thenReturn((char) 0) - .thenReturn((char) 99) - .thenReturn((char) 100) - .thenReturn((char) 101) - .thenReturn((char) 105) - .thenReturn((char) 110) - .thenReturn((char) 114) - .thenReturn((char) 116); - - //case default - Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 7); - Assert.assertTrue(NEMOparserTokenManager.curChar == 0); - //case others - Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 7); - Assert.assertTrue(NEMOparserTokenManager.curChar == 99); - Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 7); - Assert.assertTrue(NEMOparserTokenManager.curChar == 100); - Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 7); - Assert.assertTrue(NEMOparserTokenManager.curChar == 101); - Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 7); - Assert.assertTrue(NEMOparserTokenManager.curChar == 105); - Assert.assertTrue((Integer) method.invoke(class1, 0x80000000L, 0x80000000L) == 7); - Assert.assertTrue(NEMOparserTokenManager.curChar == 110); - Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 7); - Assert.assertTrue(NEMOparserTokenManager.curChar == 114); - Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 7); - Assert.assertTrue(NEMOparserTokenManager.curChar == 116); - - } - - @Test - public void testjjMoveStringLiteralDfa7_0() throws Exception{ - Method method = class1.getDeclaredMethod("jjMoveStringLiteralDfa7_0",new Class[]{ - long.class, - long.class - }); - method.setAccessible(true); - - PowerMockito.mockStatic(SimpleCharStream.class); - PowerMockito.when(SimpleCharStream.readChar()) - .thenReturn((char) 0) - .thenReturn((char) 101) - .thenReturn((char) 105) - .thenReturn((char) 111) - .thenReturn((char) 115) - .thenReturn((char) 116) - .thenReturn((char) 121) - .thenReturn((char) 121); - - //case default: - Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 8); - Assert.assertTrue(NEMOparserTokenManager.curChar == 0); - - //case others: - Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 8); - Assert.assertTrue(NEMOparserTokenManager.curChar == 101); - Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 8); - Assert.assertTrue(NEMOparserTokenManager.curChar == 105); - Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 8); - Assert.assertTrue(NEMOparserTokenManager.curChar == 111); - Assert.assertTrue((Integer) method.invoke(class1, 0x400000000L, 0x400000000L) == 8); - Assert.assertTrue(NEMOparserTokenManager.curChar == 115); - Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 8); - Assert.assertTrue(NEMOparserTokenManager.curChar == 116); - Assert.assertTrue((Integer) method.invoke(class1, 0x100000000L, 0x100000000L) == 8); - Assert.assertTrue(NEMOparserTokenManager.curChar == 121); - Assert.assertTrue((Integer) method.invoke(class1, 0x80000000000L, 0x80000000000L) == 8); - Assert.assertTrue(NEMOparserTokenManager.curChar == 121); - } - - @Test - public void testjjMoveStringLiteralDfa8_0() throws Exception{ - Method method = class1.getDeclaredMethod("jjMoveStringLiteralDfa8_0",new Class[]{ - long.class, - long.class - }); - method.setAccessible(true); - - PowerMockito.mockStatic(SimpleCharStream.class); - PowerMockito.when(SimpleCharStream.readChar()) - .thenReturn((char) 0) - .thenReturn((char) 105) - .thenReturn((char) 108) - .thenReturn((char) 110) - .thenReturn((char) 110) - .thenReturn((char) 110) - .thenReturn((char) 111); - - //case default: - Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 9); - Assert.assertTrue(NEMOparserTokenManager.curChar == 0); - - //case others - Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 9); - Assert.assertTrue(NEMOparserTokenManager.curChar == 105); - Assert.assertTrue((Integer) method.invoke(class1, 0x8000000000000L, 0x8000000000000L) == 9); - Assert.assertTrue(NEMOparserTokenManager.curChar == 108); - Assert.assertTrue((Integer) method.invoke(class1, 0x2000000000L, 0x2000000000L) == 9); - Assert.assertTrue(NEMOparserTokenManager.curChar == 110); - Assert.assertTrue((Integer) method.invoke(class1, 0x8000000000L, 0x8000000000L) == 9); - Assert.assertTrue(NEMOparserTokenManager.curChar == 110); - Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 9); - Assert.assertTrue(NEMOparserTokenManager.curChar == 110); - Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 9); - Assert.assertTrue(NEMOparserTokenManager.curChar == 111); - } - - @Test - public void testjjMoveStringLiteralDfa9_0() throws Exception{ - Method method = class1.getDeclaredMethod("jjMoveStringLiteralDfa9_0",new Class[]{ - long.class, - long.class - }); - method.setAccessible(true); - - PowerMockito.mockStatic(SimpleCharStream.class); - PowerMockito.when(SimpleCharStream.readChar()) - .thenReturn((char) 0) - .thenReturn((char) 110) - .thenReturn((char) 110) - .thenReturn((char) 111) - .thenReturn((char) 115); - - //case default: - Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 10); - Assert.assertTrue(NEMOparserTokenManager.curChar == 0); - - //case others - Assert.assertTrue((Integer) method.invoke(class1, 0x200000000L, 0x200000000L) == 10); - Assert.assertTrue(NEMOparserTokenManager.curChar == 110); - Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 10); - Assert.assertTrue(NEMOparserTokenManager.curChar == 110); - Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 10); - Assert.assertTrue(NEMOparserTokenManager.curChar == 111); - Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 10); - Assert.assertTrue(NEMOparserTokenManager.curChar == 115); - } - - @Test - public void testjjMoveStringLiteralDfa10_0() throws Exception { - Method method = class1.getDeclaredMethod("jjMoveStringLiteralDfa10_0", new Class[]{ - long.class, - long.class - }); - method.setAccessible(true); - - PowerMockito.mockStatic(SimpleCharStream.class); - PowerMockito.when(SimpleCharStream.readChar()) - .thenReturn((char) 0) - .thenReturn((char) 110) - .thenReturn((char) 115); - - //case default: - Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 11); - Assert.assertTrue(NEMOparserTokenManager.curChar == 0); - - //case others - Assert.assertTrue((Integer) method.invoke(class1, 0x100000000000L, 0x100000000000L) == 11); - Assert.assertTrue(NEMOparserTokenManager.curChar == 110); - Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 11); - Assert.assertTrue(NEMOparserTokenManager.curChar == 115); - } - - @Test - public void testjjStartNfaWithStates_0() throws Exception { - } - - @Test - public void testjjMoveNfa_0() throws Exception { - } - - @Test - public void testjjCheckNAdd() throws Exception { - Field field = class1.getDeclaredField("jjrounds"); - field.setAccessible(true); - Field field1 = class1.getDeclaredField("jjround"); - field1.setAccessible(true); - - int state = 1; - int jjrounds[] = new int[205]; - jjrounds[0] = 1; - int jjround = 1; - - } +/* + * Copyright (c) 2016 Huawei, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +/* Generated By:JavaCC: Do not edit this line. NEMOparserTokenManager.java */ +package org.opendaylight.nemo.user.vnspacemanager.languagestyle.NEMOParse; +import junit.framework.TestCase; +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.opendaylight.nemo.user.vnspacemanager.languagestyle.NEMOParse.NEMOparser; +import org.opendaylight.nemo.user.vnspacemanager.languagestyle.NEMOParse.NEMOparserTokenManager; +import org.opendaylight.nemo.user.vnspacemanager.languagestyle.NEMOParse.SimpleCharStream; +import org.opendaylight.nemo.user.vnspacemanager.languagestyle.NEMOParse.Token; + +import java.io.IOException; +import java.io.PrintStream; +import java.io.Reader; +import java.lang.reflect.Field; +import java.lang.reflect.Member; +import java.lang.reflect.Method; + +import static org.junit.Assert.*; +import static org.mockito.Mockito.*; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.api.support.membermodification.MemberMatcher; +import org.powermock.api.support.membermodification.MemberModifier; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; +/** + * Created by zhangmeng on 2015/12/17. + */ +@RunWith(PowerMockRunner.class) +@PrepareForTest(SimpleCharStream.class) +public class NEMOparserTokenManagerTest extends TestCase { + private SimpleCharStream simpleCharStream; + private int lexState; + private NEMOparserTokenManager nemOparserTokenManager; + private Class class1; + private Field field; + @Before + public void setUp() throws Exception { + class1 = NEMOparserTokenManager.class; + field = class1.getDeclaredField("input_stream"); + field.setAccessible(true); + field.set(class1,null); + + simpleCharStream = mock(SimpleCharStream.class); + lexState = 0; + } + + @Test + public void Init_ReInit() throws Exception{ + nemOparserTokenManager = new NEMOparserTokenManager(simpleCharStream); + NEMOparserTokenManager.ReInit(null); + nemOparserTokenManager = new NEMOparserTokenManager(simpleCharStream,lexState);//curLexstate = 0 + NEMOparserTokenManager.ReInit(null, lexState); + + Assert.assertTrue(field.get(class1) == null); + } + + @Test + public void testSetDebugStream() throws Exception { + NEMOparserTokenManager.setDebugStream(null); + Field field1 = class1.getField("debugStream"); + field1.setAccessible(true); + Assert.assertTrue(field1.get(class1) == null); + } + + + @Test + public void testJjFillToken() throws Exception { + nemOparserTokenManager = new NEMOparserTokenManager(simpleCharStream); + PowerMockito.mockStatic(SimpleCharStream.class); + PowerMockito.when(SimpleCharStream.GetImage()).thenReturn("test"); + Assert.assertTrue(NEMOparserTokenManager.jjFillToken() != null); + } + + @Test + public void testGetNextToken() throws Exception { + char curChar = 40; + nemOparserTokenManager = new NEMOparserTokenManager(simpleCharStream); + Assert.assertTrue(field.get(nemOparserTokenManager) == simpleCharStream); + PowerMockito.mockStatic(SimpleCharStream.class); + PowerMockito.when(SimpleCharStream.BeginToken()).thenReturn(curChar); +// System.out.println("out :" + NEMOparserTokenManager.getNextToken()); + Assert.assertTrue(NEMOparserTokenManager.getNextToken() != null); + } + + @Test + public void testjjStartNfa_0() throws Exception{ + Method method = class1.getDeclaredMethod("jjStartNfa_0",new Class[]{int.class,long.class}); + method.setAccessible(true); + int pos = 1; + long active0 = 1L; + + Assert.assertTrue((Integer) method.invoke(class1, pos, active0) == 3); +// System.out.println("method.invoke(class1,pos,active0):" + method.invoke(class1,pos,active0)); + } + + @Test + public void testjjStopStringLiteralDfa_0() throws Exception{ + Method method = class1.getDeclaredMethod("jjStopStringLiteralDfa_0",new Class[]{ + int.class, + long.class + }); + method.setAccessible(true); +// System.out.println("testjjStopStringLiteralDfa_0" + method.invoke(class1, 0, 0)); + Assert.assertTrue((Integer) method.invoke(class1, 0, 0) == -1); +// System.out.println("testjjStopStringLiteralDfa_0" + method.invoke(class1, 0, 0x74800000000000L)); + Assert.assertTrue((Integer) method.invoke(class1, 0, 0x74800000000000L) == 205); +// System.out.println("testjjStopStringLiteralDfa_0" + method.invoke(class1, 0, 0x3000000000000L)); + Assert.assertTrue((Integer) method.invoke(class1, 0, 0x3000000000000L) == 81); + //case1 + Assert.assertTrue((Integer) method.invoke(class1, 1, 0x77800000000000L) == 205); + Assert.assertTrue((Integer) method.invoke(class1, 1, 0) == -1); + //case2 + Assert.assertTrue((Integer) method.invoke(class1, 2, 0x77800000000000L) == 205); + Assert.assertTrue((Integer) method.invoke(class1, 2, 0) == -1); + //case3 + Assert.assertTrue((Integer) method.invoke(class1, 3, 0x77800000000000L) == 205); + Assert.assertTrue((Integer) method.invoke(class1, 3, 0) == -1); + //case4 + Assert.assertTrue((Integer) method.invoke(class1, 4, 0x35000000000000L) == 205); + Assert.assertTrue((Integer) method.invoke(class1, 4, 0x42800000000000L) == 205); + Assert.assertTrue((Integer) method.invoke(class1, 4, 0) == -1); + //case5 + Assert.assertTrue((Integer) method.invoke(class1, 5, 0x25000000000000L) == 205); + Assert.assertTrue((Integer) method.invoke(class1, 5, 0x10000000000000L) == 205); + Assert.assertTrue((Integer) method.invoke(class1, 5, 0) == -1); + //case6 + Assert.assertTrue((Integer) method.invoke(class1, 6, 0x5000000000000L) == 205); + Assert.assertTrue((Integer) method.invoke(class1, 6, 0x20000000000000L) == 205); + Assert.assertTrue((Integer) method.invoke(class1, 6, 0) == -1); + //case7 + Assert.assertTrue((Integer) method.invoke(class1, 7, 0x5000000000000L) == 205); + Assert.assertTrue((Integer) method.invoke(class1, 7, 0) == -1); + //case8 + Assert.assertTrue((Integer) method.invoke(class1, 8, 0x5000000000000L) == 205); + Assert.assertTrue((Integer) method.invoke(class1, 8, 0) == -1); + //case9 + Assert.assertTrue((Integer) method.invoke(class1, 9, 0x4000000000000L) == 205); + Assert.assertTrue((Integer) method.invoke(class1, 9, 0x1000000000000L) == 205); + Assert.assertTrue((Integer) method.invoke(class1, 9, 0) == -1); + //case default + Assert.assertTrue((Integer) method.invoke(class1, 10, 0) == -1); + + } + + @Test + public void testjjStopAtPos() throws Exception{ + Method method = class1.getDeclaredMethod("jjStopAtPos",new Class[]{ + int.class, + int.class + }); + method.setAccessible(true); + + Assert.assertTrue((Integer) method.invoke(class1,1,1) == 2); + } + + @Test + public void testjjMoveStringLiteralDfa0_0() throws Exception{ + Method method = class1.getDeclaredMethod("jjMoveStringLiteralDfa0_0"); + method.setAccessible(true); + Field field = class1.getDeclaredField("curChar"); + field.setAccessible(true); + + PowerMockito.mockStatic(SimpleCharStream.class); + PowerMockito.when(SimpleCharStream.readChar()).thenReturn((char) 0); + + NEMOparserTokenManager.curChar = 33; +// System.out.println("jjMoveStringLiteralDfa0_0" + method.invoke(class1)); + Assert.assertTrue((Integer) method.invoke(class1) != 0); + NEMOparserTokenManager.curChar = 38; +// System.out.println("jjMoveStringLiteralDfa0_0" + method.invoke(class1)); + Assert.assertTrue((Integer) method.invoke(class1) != 0); + NEMOparserTokenManager.curChar = 40; +// System.out.println("jjMoveStringLiteralDfa0_0" + method.invoke(class1)); + Assert.assertTrue((Integer) method.invoke(class1) != 0); + NEMOparserTokenManager.curChar = 41; +// System.out.println("jjMoveStringLiteralDfa0_0" + method.invoke(class1)); + Assert.assertTrue((Integer) method.invoke(class1) != 0); + NEMOparserTokenManager.curChar = 42; +// System.out.println("jjMoveStringLiteralDfa0_0" + method.invoke(class1)); + Assert.assertTrue((Integer) method.invoke(class1) != 0); + NEMOparserTokenManager.curChar = 43; +// System.out.println("jjMoveStringLiteralDfa0_0" + method.invoke(class1)); + Assert.assertTrue((Integer) method.invoke(class1) != 0); + NEMOparserTokenManager.curChar = 44; +// System.out.println("jjMoveStringLiteralDfa0_0" + method.invoke(class1)); + Assert.assertTrue((Integer) method.invoke(class1) != 0); + NEMOparserTokenManager.curChar = 58; +// System.out.println("jjMoveStringLiteralDfa0_0" + method.invoke(class1)); + Assert.assertTrue((Integer) method.invoke(class1) != 0); + NEMOparserTokenManager.curChar = 59; +// System.out.println("jjMoveStringLiteralDfa0_0" + method.invoke(class1)); + Assert.assertTrue((Integer) method.invoke(class1) != 0); + NEMOparserTokenManager.curChar = 60; +// System.out.println("jjMoveStringLiteralDfa0_0" + method.invoke(class1)); + Assert.assertTrue((Integer) method.invoke(class1) != 0); + NEMOparserTokenManager.curChar = 61; +// System.out.println("jjMoveStringLiteralDfa0_0" + method.invoke(class1)); + Assert.assertTrue((Integer) method.invoke(class1) != 0); + NEMOparserTokenManager.curChar = 65; +// System.out.println("jjMoveStringLiteralDfa0_0" + method.invoke(class1)); + Assert.assertTrue((Integer) method.invoke(class1) != 0); + NEMOparserTokenManager.curChar = 66; +// System.out.println("jjMoveStringLiteralDfa0_0" + method.invoke(class1)); + Assert.assertTrue((Integer) method.invoke(class1) != 0); + NEMOparserTokenManager.curChar = 67; +// System.out.println("jjMoveStringLiteralDfa0_0" + method.invoke(class1)); + Assert.assertTrue((Integer) method.invoke(class1) != 0); + NEMOparserTokenManager.curChar = 68; +// System.out.println("jjMoveStringLiteralDfa0_0" + method.invoke(class1)); + Assert.assertTrue((Integer) method.invoke(class1) != 0); + NEMOparserTokenManager.curChar = 69; +// System.out.println("jjMoveStringLiteralDfa0_0" + method.invoke(class1)); + Assert.assertTrue((Integer) method.invoke(class1) != 0); + NEMOparserTokenManager.curChar = 70; +// System.out.println("jjMoveStringLiteralDfa0_0" + method.invoke(class1)); + Assert.assertTrue((Integer) method.invoke(class1) != 0); + NEMOparserTokenManager.curChar = 73; +// System.out.println("jjMoveStringLiteralDfa0_0" + method.invoke(class1)); + Assert.assertTrue((Integer) method.invoke(class1) != 0); + NEMOparserTokenManager.curChar = 77; +// System.out.println("jjMoveStringLiteralDfa0_0" + method.invoke(class1)); + Assert.assertTrue((Integer) method.invoke(class1) != 0); + NEMOparserTokenManager.curChar = 78; +// System.out.println("jjMoveStringLiteralDfa0_0" + method.invoke(class1)); + Assert.assertTrue((Integer) method.invoke(class1) != 0); + NEMOparserTokenManager.curChar = 79; +// System.out.println("jjMoveStringLiteralDfa0_0" + method.invoke(class1)); + Assert.assertTrue((Integer) method.invoke(class1) != 0); + NEMOparserTokenManager.curChar = 80; +// System.out.println("jjMoveStringLiteralDfa0_0" + method.invoke(class1)); + Assert.assertTrue((Integer) method.invoke(class1) != 0); + NEMOparserTokenManager.curChar = 81; +// System.out.println("jjMoveStringLiteralDfa0_0" + method.invoke(class1)); + Assert.assertTrue((Integer) method.invoke(class1) != 0); + NEMOparserTokenManager.curChar = 84; +// System.out.println("jjMoveStringLiteralDfa0_0" + method.invoke(class1)); + Assert.assertTrue((Integer) method.invoke(class1) != 0); + NEMOparserTokenManager.curChar = 85; +// System.out.println("jjMoveStringLiteralDfa0_0" + method.invoke(class1)); + Assert.assertTrue((Integer) method.invoke(class1) != 0); + NEMOparserTokenManager.curChar = 91; +// System.out.println("jjMoveStringLiteralDfa0_0" + method.invoke(class1)); + Assert.assertTrue((Integer) method.invoke(class1) != 0); + NEMOparserTokenManager.curChar = 93; +// System.out.println("jjMoveStringLiteralDfa0_0" + method.invoke(class1)); + Assert.assertTrue((Integer) method.invoke(class1) != 0); + NEMOparserTokenManager.curChar = 99; +// System.out.println("jjMoveStringLiteralDfa0_0" + method.invoke(class1)); + Assert.assertTrue((Integer) method.invoke(class1) != 0); + NEMOparserTokenManager.curChar = 102; +// System.out.println("jjMoveStringLiteralDfa0_0" + method.invoke(class1)); + Assert.assertTrue((Integer) method.invoke(class1) != 0); + NEMOparserTokenManager.curChar = 105; +// System.out.println("jjMoveStringLiteralDfa0_0" + method.invoke(class1)); + Assert.assertTrue((Integer) method.invoke(class1) != 0); + NEMOparserTokenManager.curChar = 110; +// System.out.println("jjMoveStringLiteralDfa0_0" + method.invoke(class1)); + Assert.assertTrue((Integer) method.invoke(class1) != 0); + NEMOparserTokenManager.curChar = 111; +// System.out.println("jjMoveStringLiteralDfa0_0" + method.invoke(class1)); + Assert.assertTrue((Integer) method.invoke(class1) != 0); + NEMOparserTokenManager.curChar = 114; +// System.out.println("jjMoveStringLiteralDfa0_0" + method.invoke(class1)); + Assert.assertTrue((Integer) method.invoke(class1) != 0); + NEMOparserTokenManager.curChar = 115; +// System.out.println("jjMoveStringLiteralDfa0_0" + method.invoke(class1)); + Assert.assertTrue((Integer) method.invoke(class1) != 0); + NEMOparserTokenManager.curChar = 124; +// System.out.println("jjMoveStringLiteralDfa0_0" + method.invoke(class1)); + Assert.assertTrue((Integer) method.invoke(class1) != 0); + NEMOparserTokenManager.curChar = 1; +// System.out.println("jjMoveStringLiteralDfa0_0" + method.invoke(class1)); + Assert.assertTrue((Integer) method.invoke(class1) != 0); + } + + @Test + public void testjjMoveStringLiteralDfa1_0() throws Exception{ + Method method = class1.getDeclaredMethod("jjMoveStringLiteralDfa1_0",new Class[]{long.class}); + method.setAccessible(true); + + PowerMockito.mockStatic(SimpleCharStream.class); + PowerMockito.when(SimpleCharStream.readChar()) + .thenReturn((char) 0) + .thenReturn((char) 38) + .thenReturn((char) 61) + .thenReturn((char) 61) + .thenReturn((char) 61) + .thenReturn((char) 69) + .thenReturn((char) 77) + .thenReturn((char) 80) + .thenReturn((char) 82) + .thenReturn((char) 97) + .thenReturn((char) 99) + .thenReturn((char) 101) + .thenReturn((char) 108) + .thenReturn((char) 110) + .thenReturn((char) 111) + .thenReturn((char) 112) + .thenReturn((char) 114) + .thenReturn((char) 116) + .thenReturn((char) 117) + .thenReturn((char) 121) + .thenReturn((char) 124); + + //case default + Assert.assertTrue((Integer) method.invoke(class1, 1L) == 2); + Assert.assertTrue(NEMOparserTokenManager.curChar == 0); + //case 38 and so on +// System.out.println("0x8000L" + method.invoke(class1, 0x1000L)); + Assert.assertTrue((Integer) method.invoke(class1, 0x1000L) == 2); + Assert.assertTrue(NEMOparserTokenManager.curChar == 38); +// System.out.println("0x8000L" + method.invoke(class1, 0x8000L)); + Assert.assertTrue((Integer) method.invoke(class1, 0x8000L) == 2); + Assert.assertTrue(NEMOparserTokenManager.curChar == 61); +// System.out.println("0x8000L" + method.invoke(class1,0x40000L)); + Assert.assertTrue((Integer) method.invoke(class1, 0x40000L) == 2); + Assert.assertTrue(NEMOparserTokenManager.curChar == 61); +// System.out.println("0x8000L" + method.invoke(class1,0x80000L)); + Assert.assertTrue((Integer) method.invoke(class1, 0x80000L) == 2); + Assert.assertTrue(NEMOparserTokenManager.curChar == 61); +// System.out.println("0x8000L" + method.invoke(class1,0L)); + Assert.assertTrue((Integer) method.invoke(class1, 0L) == 2); + Assert.assertTrue(NEMOparserTokenManager.curChar == 69); + Assert.assertTrue((Integer) method.invoke(class1, 0L) == 2); + Assert.assertTrue(NEMOparserTokenManager.curChar == 77); + Assert.assertTrue((Integer) method.invoke(class1, 0L) == 2); + Assert.assertTrue(NEMOparserTokenManager.curChar == 80); + Assert.assertTrue((Integer) method.invoke(class1, 0L) == 2); + Assert.assertTrue(NEMOparserTokenManager.curChar == 82); + Assert.assertTrue((Integer) method.invoke(class1, 0L) == 2); + Assert.assertTrue(NEMOparserTokenManager.curChar == 97); + Assert.assertTrue((Integer) method.invoke(class1, 0L) == 2); + Assert.assertTrue(NEMOparserTokenManager.curChar == 99); + Assert.assertTrue((Integer) method.invoke(class1, 0L) == 2); + Assert.assertTrue(NEMOparserTokenManager.curChar == 101); + Assert.assertTrue((Integer) method.invoke(class1, 0L) == 2); + Assert.assertTrue(NEMOparserTokenManager.curChar == 108); + Assert.assertTrue((Integer) method.invoke(class1, 0L) == 2); + Assert.assertTrue(NEMOparserTokenManager.curChar == 110); + Assert.assertTrue((Integer) method.invoke(class1, 0L) == 2); + Assert.assertTrue(NEMOparserTokenManager.curChar == 111); + Assert.assertTrue((Integer) method.invoke(class1, 0L) == 2); + Assert.assertTrue(NEMOparserTokenManager.curChar == 112); + Assert.assertTrue((Integer) method.invoke(class1, 0L) == 2); + Assert.assertTrue(NEMOparserTokenManager.curChar == 114); + Assert.assertTrue((Integer) method.invoke(class1, 0L) == 2); + Assert.assertTrue(NEMOparserTokenManager.curChar == 116); + Assert.assertTrue((Integer) method.invoke(class1, 0L) == 2); + Assert.assertTrue(NEMOparserTokenManager.curChar == 117); + Assert.assertTrue((Integer) method.invoke(class1, 0L) == 2); + Assert.assertTrue(NEMOparserTokenManager.curChar == 121); + Assert.assertTrue((Integer) method.invoke(class1, 0L) == 2); + Assert.assertTrue(NEMOparserTokenManager.curChar == 124); + } + + @Test + public void testjjMoveStringLiteralDfa2_0() throws Exception{ + Method method = class1.getDeclaredMethod("jjMoveStringLiteralDfa2_0",new Class[]{ + long.class, + long.class + }); + method.setAccessible(true); + + PowerMockito.mockStatic(SimpleCharStream.class); + PowerMockito.when(SimpleCharStream.readChar()) + .thenReturn((char) 0) + .thenReturn((char) 68) + .thenReturn((char) 69) + .thenReturn((char) 76) + .thenReturn((char) 80) + .thenReturn((char) 97) + .thenReturn((char) 100) + .thenReturn((char) 101) + .thenReturn((char) 103) + .thenReturn((char) 105) + .thenReturn((char) 110) + .thenReturn((char) 111) + .thenReturn((char) 112) + .thenReturn((char) 114) + .thenReturn((char) 116); + + //case default +// System.out.println("0x8000L" + method.invoke(class1, 1L, 1L)); + Assert.assertTrue((Integer)method.invoke(class1,1L,1L) == 3); + Assert.assertTrue(NEMOparserTokenManager.curChar == 0); + //case others + Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 3); + Assert.assertTrue(NEMOparserTokenManager.curChar == 68); + Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 3); + Assert.assertTrue(NEMOparserTokenManager.curChar == 69); + Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 3); + Assert.assertTrue(NEMOparserTokenManager.curChar == 76); + Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 3); + Assert.assertTrue(NEMOparserTokenManager.curChar == 80); + Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 3); + Assert.assertTrue(NEMOparserTokenManager.curChar == 97); + Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 3); + Assert.assertTrue(NEMOparserTokenManager.curChar == 100); + Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 3); + Assert.assertTrue(NEMOparserTokenManager.curChar == 101); + Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 3); + Assert.assertTrue(NEMOparserTokenManager.curChar == 103); + Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 3); + Assert.assertTrue(NEMOparserTokenManager.curChar == 105); + Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 3); + Assert.assertTrue(NEMOparserTokenManager.curChar == 110); + Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 3); + Assert.assertTrue(NEMOparserTokenManager.curChar == 111); + Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 3); + Assert.assertTrue(NEMOparserTokenManager.curChar == 112); + Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 3); + Assert.assertTrue(NEMOparserTokenManager.curChar == 114); + Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 3); + Assert.assertTrue(NEMOparserTokenManager.curChar == 116); + + } + + @Test + public void testjjMoveStringLiteralDfa3_0() throws Exception{ + Method method = class1.getDeclaredMethod("jjMoveStringLiteralDfa3_0",new Class[]{ + long.class, + long.class + }); + method.setAccessible(true); + + PowerMockito.mockStatic(SimpleCharStream.class); + PowerMockito.when(SimpleCharStream.readChar()) + .thenReturn((char) 0) + .thenReturn((char) 65) + .thenReturn((char) 69) + .thenReturn((char) 79) + .thenReturn((char) 99) + .thenReturn((char) 100) + .thenReturn((char) 101) + .thenReturn((char) 103) + .thenReturn((char) 105) + .thenReturn((char) 109) + .thenReturn((char) 110) + .thenReturn((char) 111) + .thenReturn((char) 112) + .thenReturn((char) 114) + .thenReturn((char) 116) + .thenReturn((char) 119); + + //case default + Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 4); + Assert.assertTrue(NEMOparserTokenManager.curChar == 0); + //case others + Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 4); + Assert.assertTrue(NEMOparserTokenManager.curChar == 65); + Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 4); + Assert.assertTrue(NEMOparserTokenManager.curChar == 69); + Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 4); + Assert.assertTrue(NEMOparserTokenManager.curChar == 79); + Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 4); + Assert.assertTrue(NEMOparserTokenManager.curChar == 99); + Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 4); + Assert.assertTrue(NEMOparserTokenManager.curChar == 100); + Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 4); + Assert.assertTrue(NEMOparserTokenManager.curChar == 101); + Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 4); + Assert.assertTrue(NEMOparserTokenManager.curChar == 103); + Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 4); + Assert.assertTrue(NEMOparserTokenManager.curChar == 105); + Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 4); + Assert.assertTrue(NEMOparserTokenManager.curChar == 109); + Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 4); + Assert.assertTrue(NEMOparserTokenManager.curChar == 110); + Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 4); + Assert.assertTrue(NEMOparserTokenManager.curChar == 111); + Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 4); + Assert.assertTrue(NEMOparserTokenManager.curChar == 112); + Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 4); + Assert.assertTrue(NEMOparserTokenManager.curChar == 114); + Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 4); + Assert.assertTrue(NEMOparserTokenManager.curChar == 116); + Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 4); + Assert.assertTrue(NEMOparserTokenManager.curChar == 119); + + } + + @Test + public void testjjMoveStringLiteralDfa4_0() throws Exception{ + Method method = class1.getDeclaredMethod("jjMoveStringLiteralDfa4_0",new Class[]{ + long.class, + long.class + }); + method.setAccessible(true); + + PowerMockito.mockStatic(SimpleCharStream.class); + PowerMockito.when(SimpleCharStream.readChar()) + .thenReturn((char) 0) + .thenReturn((char) 77) + .thenReturn((char) 82) + .thenReturn((char) 84) + .thenReturn((char) 97) + .thenReturn((char) 101) +// .thenReturn((char) 101) + .thenReturn((char) 103) + .thenReturn((char) 104) +// .thenReturn((char) 104) + .thenReturn((char) 105) +// .thenReturn((char) 110) + .thenReturn((char) 110) + .thenReturn((char) 111) + .thenReturn((char) 114) +// .thenReturn((char) 115) +// .thenReturn((char) 115) + .thenReturn((char) 115) + .thenReturn((char) 121); + + //case default: + Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 5); + Assert.assertTrue(NEMOparserTokenManager.curChar == 0); + //case others + Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 5); + Assert.assertTrue(NEMOparserTokenManager.curChar == 77); + Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 5); + Assert.assertTrue(NEMOparserTokenManager.curChar == 82); + Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 5); + Assert.assertTrue(NEMOparserTokenManager.curChar == 84); + Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 5); + Assert.assertTrue(NEMOparserTokenManager.curChar == 97); +// Assert.assertTrue((Integer) method.invoke(class1, 0x40000000000000L, 0x40000000000000L) == 5); +// System.out.println("0x40000000000000L" + method.invoke(class1, 0x40000000000000L, 0x40000000000000L)); +// Assert.assertTrue(NEMOparserTokenManager.curChar == 101); + Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 5); + Assert.assertTrue(NEMOparserTokenManager.curChar == 101); + Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 5); + Assert.assertTrue(NEMOparserTokenManager.curChar == 103); +// System.out.println("0x40000000000000L" + method.invoke(class1, 0x1000000000L, 0x1000000000L)); +// Assert.assertTrue(NEMOparserTokenManager.curChar == 104); + Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 5); + Assert.assertTrue(NEMOparserTokenManager.curChar == 104); + Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 5); + Assert.assertTrue(NEMOparserTokenManager.curChar == 105); +// System.out.println("0x40000000000000L" + method.invoke(class1, 0x200000000000L, 0x200000000000L)); +// Assert.assertTrue(NEMOparserTokenManager.curChar == 110); + Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 5); + Assert.assertTrue(NEMOparserTokenManager.curChar == 110); + Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 5); + Assert.assertTrue(NEMOparserTokenManager.curChar == 111); + Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 5); + Assert.assertTrue(NEMOparserTokenManager.curChar == 114); + Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 5); + Assert.assertTrue(NEMOparserTokenManager.curChar == 115); + Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 5); + Assert.assertTrue(NEMOparserTokenManager.curChar == 121); + } + + @Test + public void testjjMoveStringLiteralDfa5_0() throws Exception{ + Method method = class1.getDeclaredMethod("jjMoveStringLiteralDfa5_0",new Class[]{ + long.class, + long.class + }); + method.setAccessible(true); + + PowerMockito.mockStatic(SimpleCharStream.class); + PowerMockito.when(SimpleCharStream.readChar()) + .thenReturn((char) 0) + .thenReturn((char) 69) + .thenReturn((char) 69) + .thenReturn((char) 69) + .thenReturn((char) 84) + .thenReturn((char) 97) + .thenReturn((char) 99) + .thenReturn((char) 100) + .thenReturn((char) 101) + .thenReturn((char) 103) + .thenReturn((char) 105) + .thenReturn((char) 110) + .thenReturn((char) 111) + .thenReturn((char) 114) + .thenReturn((char) 116) + .thenReturn((char) 116); + + + //case default: + Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 6); + Assert.assertTrue(NEMOparserTokenManager.curChar == 0); + //case others + Assert.assertTrue((Integer) method.invoke(class1, 0x2000000L, 0x2000000L) == 6); + Assert.assertTrue(NEMOparserTokenManager.curChar == 69); + Assert.assertTrue((Integer) method.invoke(class1, 0x10000000L, 0x10000000L) == 6); + Assert.assertTrue(NEMOparserTokenManager.curChar == 69); + Assert.assertTrue((Integer) method.invoke(class1, 0x8000000L, 0x8000000L) == 6); + Assert.assertTrue(NEMOparserTokenManager.curChar == 69); + Assert.assertTrue((Integer) method.invoke(class1, 0x4000000L, 0x4000000L) == 6); + Assert.assertTrue(NEMOparserTokenManager.curChar == 84); + Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 6); + Assert.assertTrue(NEMOparserTokenManager.curChar == 97); + Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 6); + Assert.assertTrue(NEMOparserTokenManager.curChar == 99); + Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 6); + Assert.assertTrue(NEMOparserTokenManager.curChar == 100); + Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 6); + Assert.assertTrue(NEMOparserTokenManager.curChar == 101); + Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 6); + Assert.assertTrue(NEMOparserTokenManager.curChar == 103); + Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 6); + Assert.assertTrue(NEMOparserTokenManager.curChar == 105); + Assert.assertTrue((Integer) method.invoke(class1, 0x10000000000L, 0x10000000000L) == 6); + Assert.assertTrue(NEMOparserTokenManager.curChar == 110); + Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 6); + Assert.assertTrue(NEMOparserTokenManager.curChar == 111); + Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 6); + Assert.assertTrue(NEMOparserTokenManager.curChar == 114); + Assert.assertTrue((Integer) method.invoke(class1, 0x4000000000L, 0x4000000000L) == 6); + Assert.assertTrue(NEMOparserTokenManager.curChar == 116); + Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 6); + Assert.assertTrue(NEMOparserTokenManager.curChar == 116); + } + + @Test + public void testjjMoveStringLiteralDfa6_0() throws Exception{ + Method method = class1.getDeclaredMethod("jjMoveStringLiteralDfa6_0",new Class[]{ + long.class, + long.class + }); + method.setAccessible(true); + + PowerMockito.mockStatic(SimpleCharStream.class); + PowerMockito.when(SimpleCharStream.readChar()) + .thenReturn((char) 0) + .thenReturn((char) 99) + .thenReturn((char) 100) + .thenReturn((char) 101) + .thenReturn((char) 105) + .thenReturn((char) 110) + .thenReturn((char) 114) + .thenReturn((char) 116); + + //case default + Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 7); + Assert.assertTrue(NEMOparserTokenManager.curChar == 0); + //case others + Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 7); + Assert.assertTrue(NEMOparserTokenManager.curChar == 99); + Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 7); + Assert.assertTrue(NEMOparserTokenManager.curChar == 100); + Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 7); + Assert.assertTrue(NEMOparserTokenManager.curChar == 101); + Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 7); + Assert.assertTrue(NEMOparserTokenManager.curChar == 105); + Assert.assertTrue((Integer) method.invoke(class1, 0x80000000L, 0x80000000L) == 7); + Assert.assertTrue(NEMOparserTokenManager.curChar == 110); + Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 7); + Assert.assertTrue(NEMOparserTokenManager.curChar == 114); + Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 7); + Assert.assertTrue(NEMOparserTokenManager.curChar == 116); + + } + + @Test + public void testjjMoveStringLiteralDfa7_0() throws Exception{ + Method method = class1.getDeclaredMethod("jjMoveStringLiteralDfa7_0",new Class[]{ + long.class, + long.class + }); + method.setAccessible(true); + + PowerMockito.mockStatic(SimpleCharStream.class); + PowerMockito.when(SimpleCharStream.readChar()) + .thenReturn((char) 0) + .thenReturn((char) 101) + .thenReturn((char) 105) + .thenReturn((char) 111) + .thenReturn((char) 115) + .thenReturn((char) 116) + .thenReturn((char) 121) + .thenReturn((char) 121); + + //case default: + Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 8); + Assert.assertTrue(NEMOparserTokenManager.curChar == 0); + + //case others: + Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 8); + Assert.assertTrue(NEMOparserTokenManager.curChar == 101); + Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 8); + Assert.assertTrue(NEMOparserTokenManager.curChar == 105); + Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 8); + Assert.assertTrue(NEMOparserTokenManager.curChar == 111); + Assert.assertTrue((Integer) method.invoke(class1, 0x400000000L, 0x400000000L) == 8); + Assert.assertTrue(NEMOparserTokenManager.curChar == 115); + Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 8); + Assert.assertTrue(NEMOparserTokenManager.curChar == 116); + Assert.assertTrue((Integer) method.invoke(class1, 0x100000000L, 0x100000000L) == 8); + Assert.assertTrue(NEMOparserTokenManager.curChar == 121); + Assert.assertTrue((Integer) method.invoke(class1, 0x80000000000L, 0x80000000000L) == 8); + Assert.assertTrue(NEMOparserTokenManager.curChar == 121); + } + + @Test + public void testjjMoveStringLiteralDfa8_0() throws Exception{ + Method method = class1.getDeclaredMethod("jjMoveStringLiteralDfa8_0",new Class[]{ + long.class, + long.class + }); + method.setAccessible(true); + + PowerMockito.mockStatic(SimpleCharStream.class); + PowerMockito.when(SimpleCharStream.readChar()) + .thenReturn((char) 0) + .thenReturn((char) 105) + .thenReturn((char) 108) + .thenReturn((char) 110) + .thenReturn((char) 110) + .thenReturn((char) 110) + .thenReturn((char) 111); + + //case default: + Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 9); + Assert.assertTrue(NEMOparserTokenManager.curChar == 0); + + //case others + Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 9); + Assert.assertTrue(NEMOparserTokenManager.curChar == 105); + Assert.assertTrue((Integer) method.invoke(class1, 0x8000000000000L, 0x8000000000000L) == 9); + Assert.assertTrue(NEMOparserTokenManager.curChar == 108); + Assert.assertTrue((Integer) method.invoke(class1, 0x2000000000L, 0x2000000000L) == 9); + Assert.assertTrue(NEMOparserTokenManager.curChar == 110); + Assert.assertTrue((Integer) method.invoke(class1, 0x8000000000L, 0x8000000000L) == 9); + Assert.assertTrue(NEMOparserTokenManager.curChar == 110); + Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 9); + Assert.assertTrue(NEMOparserTokenManager.curChar == 110); + Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 9); + Assert.assertTrue(NEMOparserTokenManager.curChar == 111); + } + + @Test + public void testjjMoveStringLiteralDfa9_0() throws Exception{ + Method method = class1.getDeclaredMethod("jjMoveStringLiteralDfa9_0",new Class[]{ + long.class, + long.class + }); + method.setAccessible(true); + + PowerMockito.mockStatic(SimpleCharStream.class); + PowerMockito.when(SimpleCharStream.readChar()) + .thenReturn((char) 0) + .thenReturn((char) 110) + .thenReturn((char) 110) + .thenReturn((char) 111) + .thenReturn((char) 115); + + //case default: + Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 10); + Assert.assertTrue(NEMOparserTokenManager.curChar == 0); + + //case others + Assert.assertTrue((Integer) method.invoke(class1, 0x200000000L, 0x200000000L) == 10); + Assert.assertTrue(NEMOparserTokenManager.curChar == 110); + Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 10); + Assert.assertTrue(NEMOparserTokenManager.curChar == 110); + Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 10); + Assert.assertTrue(NEMOparserTokenManager.curChar == 111); + Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 10); + Assert.assertTrue(NEMOparserTokenManager.curChar == 115); + } + + @Test + public void testjjMoveStringLiteralDfa10_0() throws Exception { + Method method = class1.getDeclaredMethod("jjMoveStringLiteralDfa10_0", new Class[]{ + long.class, + long.class + }); + method.setAccessible(true); + + PowerMockito.mockStatic(SimpleCharStream.class); + PowerMockito.when(SimpleCharStream.readChar()) + .thenReturn((char) 0) + .thenReturn((char) 110) + .thenReturn((char) 115); + + //case default: + Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 11); + Assert.assertTrue(NEMOparserTokenManager.curChar == 0); + + //case others + Assert.assertTrue((Integer) method.invoke(class1, 0x100000000000L, 0x100000000000L) == 11); + Assert.assertTrue(NEMOparserTokenManager.curChar == 110); + Assert.assertTrue((Integer) method.invoke(class1, 1L, 1L) == 11); + Assert.assertTrue(NEMOparserTokenManager.curChar == 115); + } + + @Test + public void testjjStartNfaWithStates_0() throws Exception { + } + + @Test + public void testjjMoveNfa_0() throws Exception { + } + + @Test + public void testjjCheckNAdd() throws Exception { + Field field = class1.getDeclaredField("jjrounds"); + field.setAccessible(true); + Field field1 = class1.getDeclaredField("jjround"); + field1.setAccessible(true); + + int state = 1; + int jjrounds[] = new int[205]; + jjrounds[0] = 1; + int jjround = 1; + + } } \ No newline at end of file diff --git a/nemo-impl/src/test/java/org/opendaylight/nemo/user/vnspacemanager/structurestyle/updateintent/UpdateOperationTest.java b/nemo-impl/src/test/java/org/opendaylight/nemo/user/vnspacemanager/structurestyle/updateintent/UpdateOperationTest.java index efb4d03..6872d2e 100644 --- a/nemo-impl/src/test/java/org/opendaylight/nemo/user/vnspacemanager/structurestyle/updateintent/UpdateOperationTest.java +++ b/nemo-impl/src/test/java/org/opendaylight/nemo/user/vnspacemanager/structurestyle/updateintent/UpdateOperationTest.java @@ -1,144 +1,321 @@ /* - * Copyright (c) 2015 Huawei, Inc. and others. All rights reserved. + * Copyright (c) 2016 Huawei, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ package org.opendaylight.nemo.user.vnspacemanager.structurestyle.updateintent; -import org.opendaylight.nemo.user.vnspacemanager.structurestyle.updateintent.UpdateOperation; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.*; +import junit.framework.TestCase; import org.junit.Assert; import org.junit.Before; import org.junit.Test; - -import org.opendaylight.yangtools.yang.binding.DataObject; +import com.google.common.base.Function; +import com.google.common.base.Optional; +import com.google.common.collect.Maps; +import com.google.common.util.concurrent.CheckedFuture; +import com.google.common.util.concurrent.FutureCallback; +import com.google.common.util.concurrent.Futures; +import com.google.common.util.concurrent.ListenableFuture; import org.opendaylight.controller.md.sal.binding.api.DataBroker; import org.opendaylight.controller.md.sal.binding.api.WriteTransaction; -import org.opendaylight.nemo.user.tenantmanager.TenantManage; -//import org.opendaylight.nemo.user.vnspacemanager.instancecheck.OperationInstanceCheck; -//import org.opendaylight.nemo.user.vnspacemanager.syntaxcheck.OperationDefinitionCheck; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.common.rev151010.UserId; +import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; +import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException; +import org.opendaylight.nemo.user.vnspacemanager.languagestyle.NEMOConstants; +import org.opendaylight.nemo.user.vnspacemanager.languagestyle.NEMOParse.NEMOparserConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.common.rev151010.*; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.RegisterUserInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.Users; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.engine.common.rev151010.PhysicalHostId; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.engine.common.rev151010.PhysicalNodeId; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.engine.common.rev151010.VirtualNodeId; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.user.intent.Objects; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.user.intent.objects.Connection; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.user.intent.objects.Flow; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.user.intent.objects.Node; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.user.intent.Operations; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.user.intent.TemplateDefinitions; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.user.intent.TemplateInstances; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.user.intent.objects.*; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.user.intent.operations.Operation; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.user.intent.operations.OperationBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.user.intent.operations.OperationKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.user.intent.template.definitions.TemplateDefinition; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.user.intent.template.definitions.TemplateDefinitionKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.user.intent.template.instances.TemplateInstance; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.user.intent.template.instances.TemplateInstanceKey; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.users.User; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.users.UserBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.users.UserKey; -import org.opendaylight.controller.md.sal.binding.api.WriteTransaction; -import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.common.rev151010.*; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.network.physical.hosts.PhysicalHost; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.virtual.network.rev151010.virtual.networks.virtual.network.virtual.links.VirtualLink; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.virtual.network.rev151010.virtual.networks.virtual.network.virtual.nodes.VirtualNode; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.intent.mapping.result.rev151010.intent.vn.mapping.results.user.intent.vn.mapping.IntentVnMappingResult; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.intent.mapping.result.rev151010.intent.vn.mapping.results.user.intent.vn.mapping.intent.vn.mapping.result.VirtualResource; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.user.rev151010.UserRoles; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.operation.rev151010.condition.instance.ConditionSegment.ConditionParameterMatchPattern; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.user.rev151010.user.roles.UserRole; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.user.intent.operations.Operation; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.object.rev151010.flow.instance.MatchItem; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.object.rev151010.node.instance.Property; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.object.rev151010.node.instance.SubNode; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.object.rev151010.property.instance.property.values.StringValue; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.operation.rev151010.operation.instance.Action; - -import com.google.common.util.concurrent.CheckedFuture; -import com.google.common.util.concurrent.FutureCallback; -import com.google.common.util.concurrent.Futures; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction; - -import java.util.ArrayList; -import java.util.LinkedList; -import java.util.List; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.common.rev151010.ConditionParameterName; +import java.lang.reflect.Field; +import java.util.*; +import java.util.concurrent.ExecutionException; +import static org.junit.Assert.*; +import org.opendaylight.controller.md.sal.binding.api.DataBroker; +import org.opendaylight.nemo.user.tenantmanager.TenantManage; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.common.rev151010.OperationName; +import org.opendaylight.nemo.user.vnspacemanager.languagestyle.NEMOConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.common.rev151010.*; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.user.intent.operations.Operation; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.operation.rev151010.action.definitions.ActionDefinition; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.operation.rev151010.action.instance.ParameterValues; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.operation.rev151010.condition.instance.ConditionSegment; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.operation.rev151010.condition.instance.condition.segment.ConditionParameterTargetValue; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.operation.rev151010.condition.parameter.definitions.ConditionParameterDefinition; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.operation.rev151010.condition.parameter.definitions.condition.parameter.definition.ParameterMatchPatterns; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.operation.rev151010.operation.instance.Action; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.common.rev151010.ObjectId; +import java.lang.reflect.Method; +import java.util.Map; +import static org.mockito.Mockito.*; /** - * Created by Zhongwei Zhao on 2015/12/23. + * Created by zhangmeng on 2016/1/13. */ -public class UpdateOperationTest { - - private UpdateOperation updateOperation; - +public class UpdateOperationTest extends TestCase { private DataBroker dataBroker; private TenantManage tenantManage; - private UserId userId; - private User user; - private Operation operation; - private Objects objects; - - @org.junit.Before + private UpdateOperation updateOperation; + private Class class1; + private Field field_getDefinitions; + private Field field_valueCheck; + @Before public void setUp() throws Exception { + class1 = UpdateOperation.class; + field_getDefinitions = class1.getDeclaredField("getDefinitions"); + field_getDefinitions.setAccessible(true); + field_valueCheck = class1.getDeclaredField("valueCheck"); + field_valueCheck.setAccessible(true); + dataBroker = mock(DataBroker.class); tenantManage = mock(TenantManage.class); - userId = mock(UserId.class); - user = mock(User.class); - operation = mock(Operation.class); - - updateOperation = new UpdateOperation(dataBroker, tenantManage); - objects = mock(Objects.class); + updateOperation = new UpdateOperation(dataBroker,tenantManage); } - - @org.junit.Test + + @Test public void testOperationHandling() throws Exception { - - CheckedFuture operationdefinitionFuture = mock(CheckedFuture.class); - ReadOnlyTransaction readOnlyTransaction = mock(ReadOnlyTransaction.class); - - when(dataBroker.newReadOnlyTransaction()).thenReturn(readOnlyTransaction); - when(readOnlyTransaction.read(any(LogicalDatastoreType.class), any(InstanceIdentifier.class))).thenReturn(operationdefinitionFuture); - //The action type has not been defined. - Assert.assertEquals(updateOperation.OperationHandling(userId,operation),"The action type has not been defined."); - - - when(operation.getAction()).thenReturn(null); - when(operation.getConditionSegment()).thenReturn(null); - - ObjectId objectId = mock(ObjectId.class); - when(operation.getTargetObject()).thenReturn(objectId); - //The target object is not exist. - Assert.assertEquals(updateOperation.OperationHandling(userId,operation),"The target null is not exist."); - - - when(operation.getTargetObject()).thenReturn(null); - //The target should not be empty. - Assert.assertEquals(updateOperation.OperationHandling(userId,operation),"The target should not be empty."); - - - when(operation.getTargetObject()).thenReturn(objectId); - when(tenantManage.getUser()).thenReturn(user); - when(user.getObjects()).thenReturn(objects); - - Node node = mock(Node.class); - List nodeList = new ArrayList(1); - nodeList.add(node); - when(objects.getNode()).thenReturn(nodeList); - - NodeId nodeId = mock(NodeId.class); - when(node.getNodeId()).thenReturn(nodeId); - when(nodeId.getValue()).thenReturn(new String("00001111-0000-0000-0000-000011112222")); - when(objectId.getValue()).thenReturn(new String("00001111-0000-0000-0000-000011112222")); - - WriteTransaction writeTransaction = mock(WriteTransaction.class); - when(dataBroker.newWriteOnlyTransaction()).thenReturn(writeTransaction); - - OperationId operationId = mock(OperationId.class); - when(operation.getOperationId()).thenReturn(operationId); - CheckedFuture f; - f=mock(CheckedFuture.class); - when(writeTransaction.submit()).thenReturn(f); - //null - Assert.assertEquals(updateOperation.OperationHandling(userId,operation),"The target 00001111-0000-0000-0000-000011112222 is not exist."); - + UserId userId = mock(UserId.class); + Operation operation = mock(Operation.class); + GetDefinitions getDefinitions = mock(GetDefinitions.class); + + + field_getDefinitions.set(updateOperation, getDefinitions); + + //get into method "checkDefinition" arg(operation) + ////get into method "checkAction" arg(operation) + when(operation.getAction()) + .thenReturn(mock(List.class)) + .thenReturn(null); + when(getDefinitions.getActionDefinition()).thenReturn(null); + ////get into method "checkCondition" arg(operation) + when(operation.getConditionSegment()) + .thenReturn(mock(List.class)) + .thenReturn(null); + when(getDefinitions.getConditionParameterDefinition()).thenReturn(null); + + //get into method "checkInstance" arg(userId,operation) + when(operation.getPriority()).thenReturn(null); + Assert.assertTrue(updateOperation.OperationHandling(userId, operation).equals("The priority should not be empty.")); + } + + @Test + public void testCheckInstance() throws Exception { + Method method = class1.getDeclaredMethod("checkInstance", new Class[]{ + UserId.class, + Operation.class + }); + method.setAccessible(true); + + UserId userId = mock(UserId.class); + ObjectId objectId = mock(ObjectId.class); + Operation operation = mock(Operation.class); + Operation operation1 = mock(Operation.class); + Map nodeMap = mock(Map.class); + Map flowMap = mock(Map.class); + Map connectionMap = mock(Map.class); + Map operationMap = mock(Map.class); + + when(operation.getPriority()) + .thenReturn(null) + .thenReturn(1L); + Assert.assertTrue(method.invoke(updateOperation, userId, operation).equals("The priority should not be empty.")); + verify(operation).getPriority(); + when(operation.getTargetObject()) + .thenReturn(null) + .thenReturn(objectId); + Assert.assertTrue(method.invoke(updateOperation, userId, operation).equals("The target should not be empty.")); + verify(operation).getTargetObject(); + + when(tenantManage.getOperation(userId)) + .thenReturn(operationMap) + .thenReturn(operationMap) + .thenReturn(operationMap) + .thenReturn(null); + when(operation.getOperationId()).thenReturn(mock(OperationId.class)); + when(operationMap.containsKey(operation.getOperationId())).thenReturn(true); + when(operationMap.get(operation.getOperationId())).thenReturn(operation1); + when(operation.getOperationName()).thenReturn(mock(OperationName.class)); + when(operation1.getOperationName()).thenReturn(mock(OperationName.class)); + Assert.assertTrue(method.invoke(updateOperation, userId, operation).equals("The operation name should not be changed.")); + + when(tenantManage.getOperationDataStore(userId)) + .thenReturn(operationMap) + .thenReturn(operationMap) + .thenReturn(operationMap) + .thenReturn(null); + Assert.assertTrue(method.invoke(updateOperation, userId, operation).equals("The operation name should not be changed.")); + verify(operation1,times(2)).getOperationName(); + Assert.assertTrue(method.invoke(updateOperation, userId, operation).equals("The target " + operation.getTargetObject().getValue() + " is not exist.")); + + when(tenantManage.getNode(userId)).thenReturn(nodeMap); + when(tenantManage.getConnection(userId)).thenReturn(connectionMap); + when(tenantManage.getFlow(userId)).thenReturn(flowMap); + when(tenantManage.getNodeDataStore(userId)).thenReturn(nodeMap); + when(tenantManage.getConnectionDataStore(userId)).thenReturn(connectionMap); + when(tenantManage.getFlowDataStore(userId)).thenReturn(flowMap); + when(nodeMap.containsKey(new NodeId(operation.getTargetObject()))).thenReturn(true); + when(connectionMap.containsKey(new ConnectionId(operation.getTargetObject()))).thenReturn(true); + when(flowMap.containsKey(new FlowId(operation.getTargetObject()))).thenReturn(true); + Assert.assertTrue(method.invoke(updateOperation, userId, operation) == null); + verify(nodeMap,times(2)).containsKey(new NodeId(operation.getTargetObject())); + verify(connectionMap,times(2)).containsKey(new ConnectionId(operation.getTargetObject())); + verify(flowMap,times(2)).containsKey(new FlowId(operation.getTargetObject())); + } + + @Test + public void testCheckAction() throws Exception { + Method method = class1.getDeclaredMethod("checkAction", new Class[]{Operation.class}); + method.setAccessible(true); + + Action action = mock(Action.class); + ActionName actionName = mock(ActionName.class); + Operation operation = mock(Operation.class); + ParameterValues parameterValues = mock(ParameterValues.class); + GetDefinitions getDefinitions = mock(GetDefinitions.class); + ActionDefinition.ParameterValueType parameterValueType = ActionDefinition.ParameterValueType.Int; + List actionList = new ArrayList(); + Map actionDefinitionMap = mock(Map.class); + + field_getDefinitions.set(updateOperation, getDefinitions); + actionList.add(action); + + when(getDefinitions.getActionDefinition()).thenReturn(actionDefinitionMap); + when(operation.getAction()) + .thenReturn(null) + .thenReturn(actionList); + //test null + Assert.assertTrue(method.invoke(updateOperation, operation) == null); + verify(getDefinitions).getActionDefinition(); + + //test empty + when(actionDefinitionMap.isEmpty()) + .thenReturn(true) + .thenReturn(false); + Assert.assertTrue(method.invoke(updateOperation, operation).equals("The action type has not been defined.")); + verify(getDefinitions, times(2)).getActionDefinition(); + //test not empty + when(action.getActionName()).thenReturn(actionName); + when(actionDefinitionMap.containsKey(action.getActionName())) + .thenReturn(false) + .thenReturn(true); + Assert.assertTrue(method.invoke(updateOperation, operation).equals("The action type has not been defined.")); + verify(actionDefinitionMap).containsKey(action.getActionName()); + + when(action.getParameterValues()).thenReturn(parameterValues); + when(actionDefinitionMap.get(action.getActionName())).thenReturn(mock(ActionDefinition.class)); + when(actionDefinitionMap.get(action.getActionName()).getParameterValueType()) + .thenReturn(ActionDefinition.ParameterValueType.String) + .thenReturn(parameterValueType) + .thenReturn(ActionDefinition.ParameterValueType.Range); + when(parameterValues.getIntValue()).thenReturn(null); + when(parameterValues.getStringValue()).thenReturn(null); + when(parameterValues.getRangeValue()).thenReturn(null); + //org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.operation.rev151010.action.instance.parameter.values.IntValue + Assert.assertTrue(method.invoke(updateOperation, operation).equals("The value type of" + action.getActionName().toString() + "should be string.")); + Assert.assertTrue(method.invoke(updateOperation, operation).equals("The value type of" + action.getActionName().toString() + "should be integer.")); + Assert.assertTrue(method.invoke(updateOperation, operation).equals("The value type of" + action.getActionName().toString() + "should be range.")); + + } + + @Test + public void testCheckCondition() throws Exception { + Method method = class1.getDeclaredMethod("checkCondition", new Class[]{Operation.class}); + method.setAccessible(true); + + ValueCheck valueCheck = mock(ValueCheck.class); + Operation operation = mock(Operation.class); + ConditionSegment conditionSegment = mock(ConditionSegment.class); + ConditionParameterName conditionParameterName = mock(ConditionParameterName.class); + GetDefinitions getDefinitions = mock(GetDefinitions.class); + ConditionParameterTargetValue conditionParameterTargetValue = mock(ConditionParameterTargetValue.class); + ParameterMatchPatterns parameterMatchPatterns = mock(ParameterMatchPatterns.class); + ConditionParameterMatchPattern conditionParameterMatchPattern = ConditionParameterMatchPattern.Equal; + ConditionParameterDefinition conditionParameterDefinition = mock(ConditionParameterDefinition.class); + List conditionParameterMatchPatterns = new ArrayList(); + List conditionSegmentList = new ArrayList(); + Map conditionParameterDefinitionMap = mock(Map.class); + + field_getDefinitions.set(updateOperation, getDefinitions); + field_valueCheck.set(updateOperation, valueCheck); + conditionSegmentList.add(conditionSegment); + conditionParameterMatchPatterns.add(ParameterMatchPatterns.ParameterMatchPattern.NotEqual); + + when(getDefinitions.getConditionParameterDefinition()).thenReturn(conditionParameterDefinitionMap); + when(operation.getConditionSegment()) + .thenReturn(null) + .thenReturn(conditionSegmentList); + Assert.assertTrue(method.invoke(updateOperation, operation) == null); + + when(conditionParameterDefinitionMap.isEmpty()) + .thenReturn(true) + .thenReturn(false); + Assert.assertTrue(method.invoke(updateOperation, operation).equals("This condition has not been defined in data store.")); + + when(conditionSegment.getConditionParameterName()).thenReturn(conditionParameterName); + when(conditionParameterName.getValue()).thenReturn(NEMOConstants.time); + when(conditionParameterDefinitionMap.containsKey(new ParameterName(conditionSegment.getConditionParameterName().getValue()))) + .thenReturn(false) + .thenReturn(true); + Assert.assertTrue(method.invoke(updateOperation, operation).equals("This condition has not been defined in data store.")); + + when(conditionParameterDefinitionMap.get(new ParameterName(conditionSegment.getConditionParameterName().getValue()))) + .thenReturn(conditionParameterDefinition); + when(conditionSegment.getConditionParameterMatchPattern()).thenReturn(conditionParameterMatchPattern); + when(conditionParameterDefinition.getParameterMatchPatterns()) + .thenReturn(null) + .thenReturn(parameterMatchPatterns); + Assert.assertTrue(method.invoke(updateOperation, operation).equals("No match patterns have been defined in data store.")); + + when(conditionParameterDefinition.getParameterMatchPatterns().getParameterMatchPattern()) + .thenReturn(null) + .thenReturn(conditionParameterMatchPatterns); + when(conditionSegment.getConditionParameterTargetValue()).thenReturn(conditionParameterTargetValue); + when(conditionSegment.getConditionParameterTargetValue().getStringValue()).thenReturn("test"); + when(valueCheck.checkTime(conditionSegment.getConditionParameterTargetValue().getStringValue())).thenReturn(false); + Assert.assertTrue(method.invoke(updateOperation, operation).equals("There are no match pattern in match pattrn list.")); + Assert.assertTrue(method.invoke(updateOperation, operation).equals("The " + NEMOConstants.time + " is not legal.")); + + conditionParameterMatchPatterns.clear(); + conditionParameterMatchPatterns.add(ParameterMatchPatterns.ParameterMatchPattern.Equal); + Assert.assertTrue(method.invoke(updateOperation, operation).equals("The " + NEMOConstants.time + " is not legal.")); + + when(conditionParameterDefinition.getParameterValueType()) + .thenReturn(ConditionParameterDefinition.ParameterValueType.String) + .thenReturn(ConditionParameterDefinition.ParameterValueType.String) + .thenReturn(ConditionParameterDefinition.ParameterValueType.Int) + .thenReturn(ConditionParameterDefinition.ParameterValueType.Int) + .thenReturn(ConditionParameterDefinition.ParameterValueType.Range) + .thenReturn(ConditionParameterDefinition.ParameterValueType.Range); + when(conditionParameterTargetValue.getIntValue()).thenReturn(null); + when(conditionParameterTargetValue.getStringValue()).thenReturn(null); + when(conditionParameterTargetValue.getRangeValue()).thenReturn(null); +// System.out.println(method.invoke(updateOperation, operation)); +// System.out.println(method.invoke(updateOperation, operation)); +// System.out.println(method.invoke(updateOperation, operation)); + Assert.assertTrue(method.invoke(updateOperation, operation).equals("The value type of " + conditionSegment.getConditionParameterName().getValue() + " should be string.")); + Assert.assertTrue(method.invoke(updateOperation, operation).equals("The value type of " + conditionSegment.getConditionParameterName().getValue() + " should be integer.")); + Assert.assertTrue(method.invoke(updateOperation, operation).equals("The value type of " + conditionSegment.getConditionParameterName().getValue() + " should be range.")); + } } \ No newline at end of file diff --git a/nemo-tools/sandbox/pom.xml b/nemo-tools/sandbox/pom.xml index e8adf01..a53d517 100644 --- a/nemo-tools/sandbox/pom.xml +++ b/nemo-tools/sandbox/pom.xml @@ -30,9 +30,28 @@ and is available at http://www.eclipse.org/legal/epl-v10.html 1.0-SNAPSHOT 262 20090211 + 1.5.2 + + org.powermock + powermock-core + ${powermock.version} + test + + + org.powermock + powermock-module-junit4 + ${powermock.version} + test + + + org.powermock + powermock-api-mockito + ${powermock.version} + test + org.slf4j slf4j-log4j12 diff --git a/nemo-tools/sandbox/src/test/java/org/opendaylight/nemo/tool/sandbox/CliTest.java b/nemo-tools/sandbox/src/test/java/org/opendaylight/nemo/tool/sandbox/CliTest.java new file mode 100644 index 0000000..8503373 --- /dev/null +++ b/nemo-tools/sandbox/src/test/java/org/opendaylight/nemo/tool/sandbox/CliTest.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2016 Huawei, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.nemo.tool.sandbox; + +import junit.framework.TestCase; +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.*; +import asg.cliche.Command; +import asg.cliche.Shell; +import asg.cliche.ShellDependent; +import static org.mockito.Mockito.*; +/** + * Created by zhangmeng on 2016/1/14. + */ +public class CliTest extends TestCase { + private Cli cli; + @Before + public void setUp() throws Exception { + cli = new Cli(); + } + + @Test + public void testCliSetShell() throws Exception { + Shell shell = mock(Shell.class); + cli.cliSetShell(shell); + } + + @Test + public void testInstall() throws Exception { + cli.install(); + } + + @Test + public void testUninstall() throws Exception { + cli.uninstall(); + } +} \ No newline at end of file diff --git a/nemo-tools/sandbox/src/test/java/org/opendaylight/nemo/tool/sandbox/CmdExecutorTest.java b/nemo-tools/sandbox/src/test/java/org/opendaylight/nemo/tool/sandbox/CmdExecutorTest.java new file mode 100644 index 0000000..32ab69e --- /dev/null +++ b/nemo-tools/sandbox/src/test/java/org/opendaylight/nemo/tool/sandbox/CmdExecutorTest.java @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2016 Huawei, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.nemo.tool.sandbox; + +import junit.framework.TestCase; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import java.awt.color.CMMException; + +import static org.junit.Assert.*; +import ch.ethz.ssh2.Connection; +import ch.ethz.ssh2.Session; +import ch.ethz.ssh2.StreamGobbler; +import org.junit.runner.RunWith; +import org.opendaylight.nemo.tool.sandbox.utils.Config; +import org.opendaylight.nemo.tool.sandbox.utils.FileUtils; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.api.support.membermodification.MemberMatcher; +import org.powermock.api.support.membermodification.MemberModifier; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.lang.reflect.Field; +import java.lang.reflect.Method; + +import static org.mockito.Mockito.*; +/** + * Created by zhangmeng on 2016/1/14. + */ +@RunWith(PowerMockRunner.class) +@PrepareForTest(ch.ethz.ssh2.Connection.class) +public class CmdExecutorTest extends TestCase { + private CmdExecutor cmdExecutor; + private Class class1; + private Field field_sshConnection; + @Before + public void setUp() throws Exception { + class1 = CmdExecutor.class; + field_sshConnection = class1.getDeclaredField("sshConnection"); + field_sshConnection.setAccessible(true); + + cmdExecutor = new CmdExecutor(); + } + + @Test + public void testOpen() throws Exception { + String command = "cd ~"; + Session session = mock(Session.class); + Connection sshConnection = mock(Connection.class); + + Assert.assertTrue(CmdExecutor.open() == false); + PowerMockito.whenNew(Connection.class).withArguments(any(String.class)).thenReturn(sshConnection); + when(sshConnection.authenticateWithPassword(any(String.class), any(String.class))).thenReturn(true); + Assert.assertTrue(CmdExecutor.open() == false); +// Assert.assertTrue(field_sshConnection.get(class1) == sshConnection); +// verify(sshConnection).authenticateWithPassword(any(String.class), any(String.class)); + + field_sshConnection.set(class1, sshConnection); + when(sshConnection.openSession()).thenReturn(session); + doNothing().when(session).execCommand(command); + when(session.getStdout()).thenReturn(mock(InputStream.class)); + Assert.assertTrue(CmdExecutor.sshExecute(command) != null); + verify(session).getStdout(); + CmdExecutor.queryInterfaceMac("eth0"); + CmdExecutor.queryInterfaceMac("1","eth0"); + + CmdExecutor.close(); + } + + @Test + public void testgetMacFromResult() throws Exception { + Method method = class1.getDeclaredMethod("getMacFromResult",new Class[]{ + String.class + }); + method.setAccessible(true); + Assert.assertTrue(method.invoke(class1,"HWaddr") != null); + } + +} \ No newline at end of file diff --git a/nemo-tools/sandbox/src/test/java/org/opendaylight/nemo/tool/sandbox/EasyCliTest.java b/nemo-tools/sandbox/src/test/java/org/opendaylight/nemo/tool/sandbox/EasyCliTest.java new file mode 100644 index 0000000..fe9d689 --- /dev/null +++ b/nemo-tools/sandbox/src/test/java/org/opendaylight/nemo/tool/sandbox/EasyCliTest.java @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2016 Huawei, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.nemo.tool.sandbox; + +import junit.framework.TestCase; +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.*; +import asg.cliche.Shell; +import asg.cliche.ShellFactory; + +import java.io.IOException; +import java.lang.reflect.Field; +import static org.mockito.Mockito.*; + +/** + * Created by zhangmeng on 2016/1/14. + */ +public class EasyCliTest extends TestCase { + private EasyCli easyCli; + @Before + public void setUp() throws Exception { + easyCli = new EasyCli("1","2","3"); + } + + @Test + public void testAdd() throws Exception { + easyCli.add("4"); + } + + @Test + public void testRun() throws Exception { + Field field = EasyCli.class.getDeclaredField("shell"); + field.setAccessible(true); + + Shell shell = mock(Shell.class); + + field.set(easyCli,shell); + doNothing().when(shell).commandLoop(); + easyCli.run(); + verify(shell).commandLoop(); + } +} \ No newline at end of file diff --git a/nemo-tools/sandbox/src/test/java/org/opendaylight/nemo/tool/sandbox/SandBoxManagerTest.java b/nemo-tools/sandbox/src/test/java/org/opendaylight/nemo/tool/sandbox/SandBoxManagerTest.java new file mode 100644 index 0000000..f534982 --- /dev/null +++ b/nemo-tools/sandbox/src/test/java/org/opendaylight/nemo/tool/sandbox/SandBoxManagerTest.java @@ -0,0 +1,252 @@ +/* + * Copyright (c) 2016 Huawei, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.nemo.tool.sandbox; + +import junit.framework.Assert; +import junit.framework.TestCase; +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.*; +import org.json.JSONObject; +import org.junit.runner.RunWith; +import org.opendaylight.nemo.tool.sandbox.models.*; +import org.opendaylight.nemo.tool.sandbox.utils.PropertyLoader; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.api.support.membermodification.MemberMatcher; +import org.powermock.api.support.membermodification.MemberModifier; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.*; +/** + * Created by zhangmeng on 2016/1/14. + */ +@RunWith(PowerMockRunner.class) +@PrepareForTest(CmdExecutor.class) +public class SandBoxManagerTest extends TestCase { + private SandBoxManager sandBoxManager; + private Method method; + @Before + public void setUp() throws Exception { + sandBoxManager = SandBoxManager.getInstance(); + } + + @Test + public void testGetInstance() throws Exception { + sandBoxManager = SandBoxManager.getInstance(); + } + + @Test + public void testGets() throws Exception { + Field field = SandBoxManager.class.getDeclaredField("network"); + field.setAccessible(true); + + Network network = mock(Network.class); + JSONObject jsonObject = mock(JSONObject.class); + + //no powermock and network=null + field.set(sandBoxManager, null); + org.junit.Assert.assertTrue(!sandBoxManager.createNetwork(null)); + org.junit.Assert.assertTrue(!sandBoxManager.createNetwork()); + org.junit.Assert.assertTrue(sandBoxManager.getHosts() == null); + org.junit.Assert.assertTrue(sandBoxManager.getExternals() == null); + org.junit.Assert.assertTrue(sandBoxManager.getSwitches() == null); + org.junit.Assert.assertTrue(sandBoxManager.getLinks() == null); + org.junit.Assert.assertTrue(sandBoxManager.destroyNetwork()); + + field.set(sandBoxManager, network); + PowerMockito.mockStatic(CmdExecutor.class); + PowerMockito.when(CmdExecutor.open()).thenReturn(true); + when(network.hostJsonNode()).thenReturn(jsonObject); + when(network.externalJsonNode()).thenReturn(jsonObject); + when(network.nodeJsonNode()).thenReturn(jsonObject); + when(network.innerLinkJsonNode()).thenReturn(jsonObject); + when(network.execute(any(String.class), any(String.class))).thenReturn("test"); + org.junit.Assert.assertTrue(sandBoxManager.execute("1","1").equals("test")); + org.junit.Assert.assertTrue(sandBoxManager.getHosts() != null); + org.junit.Assert.assertTrue(sandBoxManager.getExternals() != null); + org.junit.Assert.assertTrue(sandBoxManager.getSwitches() != null); + org.junit.Assert.assertTrue(sandBoxManager.getLinks() != null); + + org.junit.Assert.assertTrue(sandBoxManager.createNetwork(PropertyLoader.readLines("/Network", "Network file does not exist."))); + org.junit.Assert.assertTrue(sandBoxManager.createNetwork()); + org.junit.Assert.assertTrue(sandBoxManager.destroyNetwork()); + } + @Test + public void testGetNodeType() throws Exception { + method = SandBoxManager.class.getDeclaredMethod("getNodeType",new Class[]{String.class}); + method.setAccessible(true); + + org.junit.Assert.assertTrue(method.invoke(sandBoxManager, "Switch") == NodeType.SWITCH); + org.junit.Assert.assertTrue(method.invoke(sandBoxManager, "Router") == NodeType.ROUTER); + org.junit.Assert.assertTrue(method.invoke(sandBoxManager, "Cache") == NodeType.CACHE); + org.junit.Assert.assertTrue(method.invoke(sandBoxManager, "Firewall") == NodeType.FIREWALL); + org.junit.Assert.assertTrue(method.invoke(sandBoxManager, "Vm") == NodeType.VM); + org.junit.Assert.assertTrue(method.invoke(sandBoxManager,"1") == NodeType.UNKNOWN); + + } + + @Test + public void testHandleLink() throws Exception { + method = SandBoxManager.class.getDeclaredMethod("handleLink",new Class[]{String.class}); + method.setAccessible(true); + + org.junit.Assert.assertTrue(method.invoke(sandBoxManager, "12") == null); + org.junit.Assert.assertTrue(method.invoke(sandBoxManager,"1,2,3,4,5") != null); + } + + @Test + public void testSaveConnector() throws Exception { + method = SandBoxManager.class.getDeclaredMethod("saveConnector",new Class[]{ + Connector.class, + Map.class + }); + method.setAccessible(true); + + Connector connector = mock(Connector.class); + Map> connectorMap = mock(Map.class); + + when(connector.getNodeName()).thenReturn("test"); + when(connectorMap.containsKey(any(String.class))) + .thenReturn(true) + .thenReturn(false); + when(connectorMap.get(any(String.class))).thenReturn(mock(List.class)); + method.invoke(sandBoxManager, connector, connectorMap); + method.invoke(sandBoxManager, connector, connectorMap); + verify(connectorMap,times(2)).containsKey(any(String.class)); + } + + @Test + public void testParserHost() throws Exception { + method = SandBoxManager.class.getDeclaredMethod("parserHost",new Class[]{ + String[].class, + Map.class, + Host.class + }); + method.setAccessible(true); + + String[] args = {"1","2","3","1:2"}; + Map> connectorMap = mock(Map.class); + Host host = mock(Host.class); + Connector connector = mock(Connector.class); + List connectors = new ArrayList(); + + connectors.add(connector); + + when(host.getName()).thenReturn("test"); + when(connectorMap.get(host.getName())).thenReturn(connectors); + + method.invoke(sandBoxManager, args, connectorMap, host); + verify(host,times(2)).getName(); + } + + @Test + public void testHandleFirewall() throws Exception { + method = SandBoxManager.class.getDeclaredMethod("handleFirewall",new Class[]{ + String.class, + Map.class + }); + method.setAccessible(true); + + String line = "test"; + Map> connectorMap = mock(Map.class); + + org.junit.Assert.assertTrue(method.invoke(sandBoxManager,line,connectorMap) == null); + line = "1,2,3,1:2"; + when(connectorMap.get(any(String.class))).thenReturn(null); + org.junit.Assert.assertTrue(method.invoke(sandBoxManager,line,connectorMap) != null); + } + + @Test + public void testHandleCache() throws Exception { + method = SandBoxManager.class.getDeclaredMethod("handleCache",new Class[]{ + String.class, + Map.class + }); + method.setAccessible(true); + + String line = "test"; + Map> connectorMap = mock(Map.class); + + org.junit.Assert.assertTrue(method.invoke(sandBoxManager,line,connectorMap) == null); + line = "1,2,3,1:2"; + when(connectorMap.get(any(String.class))).thenReturn(null); + org.junit.Assert.assertTrue(method.invoke(sandBoxManager,line,connectorMap) != null); + + } + + @Test + public void testHandleVirtualMachine() throws Exception { + method = SandBoxManager.class.getDeclaredMethod("handleVirtualMachine",new Class[]{ + String.class, + Map.class + }); + method.setAccessible(true); + + String line = "test"; + Map> connectorMap = mock(Map.class); + + org.junit.Assert.assertTrue(method.invoke(sandBoxManager,line,connectorMap) == null); + line = "1,2,3,1:2"; + when(connectorMap.get(any(String.class))).thenReturn(null); + org.junit.Assert.assertTrue(method.invoke(sandBoxManager,line,connectorMap) != null); + } + + @Test + public void testHandleSwitch() throws Exception { + method = SandBoxManager.class.getDeclaredMethod("handleSwitch",new Class[]{ + String.class, + Map.class + }); + method.setAccessible(true); + + List connectorList = new ArrayList(); + Connector connector = mock(Connector.class); + String line = "test"; + Map> connectorMap = mock(Map.class); + + connectorList.add(connector); + + org.junit.Assert.assertTrue(method.invoke(sandBoxManager, line, connectorMap) == null); + line = "Router,2,3"; + when(connectorMap.get(any(String.class))).thenReturn(connectorList); + org.junit.Assert.assertTrue(method.invoke(sandBoxManager, line, connectorMap) != null); + + } + + @Test + public void testGenerateNetwork() throws Exception { + method = SandBoxManager.class.getDeclaredMethod("generateNetwork",new Class[]{List.class}); + method.setAccessible(true); + + List list = new ArrayList(); + list.add("Switch"); + method.invoke(sandBoxManager, list); + list.clear(); + list.add("Vm"); + method.invoke(sandBoxManager, list); + list.clear(); + list.add("Cache"); + method.invoke(sandBoxManager, list); + list.clear(); + list.add("Firewall"); + method.invoke(sandBoxManager, list); + + } +} \ No newline at end of file diff --git a/nemo-tools/sandbox/src/test/java/org/opendaylight/nemo/tool/sandbox/models/CacheTest.java b/nemo-tools/sandbox/src/test/java/org/opendaylight/nemo/tool/sandbox/models/CacheTest.java new file mode 100644 index 0000000..37b58b8 --- /dev/null +++ b/nemo-tools/sandbox/src/test/java/org/opendaylight/nemo/tool/sandbox/models/CacheTest.java @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2016 Huawei, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.nemo.tool.sandbox.models; + +import junit.framework.TestCase; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import static org.mockito.Mockito.*; +import static org.junit.Assert.*; + +import org.junit.runner.RunWith; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.api.support.membermodification.MemberMatcher; +import org.powermock.api.support.membermodification.MemberModifier; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; +import org.opendaylight.nemo.tool.sandbox.CmdExecutor; + +import java.lang.reflect.Method; +import java.lang.reflect.Field; + +/** + * Created by Thomas Liu on 2016/1/14. + */ +@RunWith(PowerMockRunner.class) +@PrepareForTest({CmdExecutor.class}) +public class CacheTest extends TestCase { + String name,uuId; + Cache cacheTest; + private Method method; + private Class class1; + private Connector connector; + + + @Before + public void setUp() throws Exception { + name = new String("name1"); + uuId = new String("11111111-1111-1111-1111-111111111111"); + cacheTest = new Cache(name,uuId); + class1 = Cache.class; + org.opendaylight.nemo.tool.sandbox.models.Connector connector = mock(org.opendaylight.nemo.tool.sandbox.models.Connector.class); + cacheTest.addConnectors(connector); + } + + @Test + public void testGenerateCommands() throws Exception { + method = class1.getDeclaredMethod("generateCommands",new Class[]{}); + method.setAccessible(true); + Assert.assertNotNull(method.invoke(cacheTest)); + } + + @Test + public void testUninstall() throws Exception { + PowerMockito.mockStatic(CmdExecutor.class); + PowerMockito.when(CmdExecutor.sshExecute(any(String.class))).thenReturn("null"); + cacheTest.uninstall(); + + } + +} \ No newline at end of file diff --git a/nemo-tools/sandbox/src/test/java/org/opendaylight/nemo/tool/sandbox/models/ConnectorTest.java b/nemo-tools/sandbox/src/test/java/org/opendaylight/nemo/tool/sandbox/models/ConnectorTest.java new file mode 100644 index 0000000..d7fe784 --- /dev/null +++ b/nemo-tools/sandbox/src/test/java/org/opendaylight/nemo/tool/sandbox/models/ConnectorTest.java @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2016 Huawei, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.nemo.tool.sandbox.models; + +import junit.framework.TestCase; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.opendaylight.nemo.tool.sandbox.models.Connector; + +import static org.mockito.Mockito.*; +import static org.junit.Assert.*; + +import static org.junit.Assert.*; + +/** + * Created by Thomas Liu on 2016/1/14. + */ +public class ConnectorTest extends TestCase { + private int order; + private String nodeName; + private Connector connectorTest; + + @Before + public void setUp() throws Exception { + order = 10; + nodeName = "connector"; + connectorTest = new Connector(nodeName,order); + + } + + @Test + public void testGetConnectorName() throws Exception { + Assert.assertNotNull(connectorTest.getConnectorName()); + } + + @Test + public void testGetOrder() throws Exception { + Assert.assertNotNull(connectorTest.getOrder()); + } + + @Test + public void testGetNodeName() throws Exception { + Assert.assertNotNull(connectorTest.getNodeName()); + } + + @Test + public void testEquals() throws Exception { + Assert.assertNotNull(connectorTest.equals(this)); + + } + + @Test + public void testHashCode() throws Exception { + Assert.assertNotNull(connectorTest.hashCode()); + } + + @Test + public void testToString() throws Exception { + Assert.assertNotNull(connectorTest.toString()); + } + + @Test + public void testCompareTo() throws Exception { + Assert.assertNotNull(connectorTest.compareTo(new Connector("connector2",5))); + } +} \ No newline at end of file diff --git a/nemo-tools/sandbox/src/test/java/org/opendaylight/nemo/tool/sandbox/models/FirewallTest.java b/nemo-tools/sandbox/src/test/java/org/opendaylight/nemo/tool/sandbox/models/FirewallTest.java new file mode 100644 index 0000000..6d2ad88 --- /dev/null +++ b/nemo-tools/sandbox/src/test/java/org/opendaylight/nemo/tool/sandbox/models/FirewallTest.java @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2016 Huawei, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.nemo.tool.sandbox.models; + +import junit.framework.TestCase; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import static org.mockito.Mockito.*; +import static org.junit.Assert.*; + +import org.junit.runner.RunWith; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.api.support.membermodification.MemberMatcher; +import org.powermock.api.support.membermodification.MemberModifier; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; +import org.opendaylight.nemo.tool.sandbox.CmdExecutor; +import org.opendaylight.nemo.tool.sandbox.models.Firewall; + +import java.lang.reflect.Method; +import java.lang.reflect.Field; + +/** + * Created by Thomas Liu on 2016/1/14. + */ +@RunWith(PowerMockRunner.class) +@PrepareForTest({CmdExecutor.class}) +public class FirewallTest extends TestCase { + + String name,uuId; + Firewall firewallTest; + private Method method; + private Class class1; + private Connector connector; + + @Before + public void setUp() throws Exception { + name = new String("name1"); + uuId = new String("11111111-1111-1111-1111-111111111111"); + firewallTest = new Firewall(name,uuId); + class1 = Firewall.class; + org.opendaylight.nemo.tool.sandbox.models.Connector connector = mock(org.opendaylight.nemo.tool.sandbox.models.Connector.class); + firewallTest.addConnectors(connector); + + } + + @Test + public void testGenerateCommands() throws Exception { + method = class1.getDeclaredMethod("generateCommands",new Class[]{}); + method.setAccessible(true); + Assert.assertNotNull(method.invoke(firewallTest)); + + } + + @Test + public void testUninstall() throws Exception { + PowerMockito.mockStatic(CmdExecutor.class); + PowerMockito.when(CmdExecutor.sshExecute(any(String.class))).thenReturn("null"); + firewallTest.uninstall(); + + } +} \ No newline at end of file diff --git a/nemo-tools/sandbox/src/test/java/org/opendaylight/nemo/tool/sandbox/models/LinkTest.java b/nemo-tools/sandbox/src/test/java/org/opendaylight/nemo/tool/sandbox/models/LinkTest.java new file mode 100644 index 0000000..2faf1a5 --- /dev/null +++ b/nemo-tools/sandbox/src/test/java/org/opendaylight/nemo/tool/sandbox/models/LinkTest.java @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2016 Huawei, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.nemo.tool.sandbox.models; +import junit.framework.TestCase; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import static org.mockito.Mockito.*; +import static org.junit.Assert.*; + +import org.opendaylight.nemo.tool.sandbox.CmdExecutor; +import org.opendaylight.nemo.tool.sandbox.models.Connector; + +import org.junit.runner.RunWith; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.api.support.membermodification.MemberMatcher; +import org.powermock.api.support.membermodification.MemberModifier; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +/** + * Created by Thomas Liu on 2016/1/14. + */ +@RunWith(PowerMockRunner.class) +@PrepareForTest({CmdExecutor.class}) +public class LinkTest extends TestCase { + + private Connector srcInterface; + private Connector dstInterface; + private Link likeTest; + + @Before + public void setUp() throws Exception { + srcInterface = new Connector("src",1); + dstInterface = new Connector("dst",2); + likeTest = new Link(srcInterface,dstInterface); + + } + + @Test + public void testGetSrcConnector() throws Exception { + Assert.assertNotNull(likeTest.getSrcConnector()); + } + + @Test + public void testGetDstConnector() throws Exception { + Assert.assertNotNull(likeTest.getDstConnector()); + } + + @Test + public void testInstall() throws Exception { + PowerMockito.mockStatic(CmdExecutor.class); + PowerMockito.when(CmdExecutor.sshExecute(any(String.class))).thenReturn("null"); + likeTest.install(); + } + + @Test + public void testUninstall() throws Exception { + PowerMockito.mockStatic(CmdExecutor.class); + PowerMockito.when(CmdExecutor.sshExecute(any(String.class))).thenReturn("null"); + likeTest.uninstall(); + } + + @Test + public void testEquals() throws Exception { + Assert.assertNotNull(likeTest.equals(this)); + } + + @Test + public void testHashCode() throws Exception { + Assert.assertNotNull(likeTest.hashCode()); + } + + @Test + public void testToString() throws Exception { + Assert.assertNotNull(likeTest.toString()); + } +} \ No newline at end of file diff --git a/nemo-tools/sandbox/src/test/java/org/opendaylight/nemo/tool/sandbox/models/NetworkTest.java b/nemo-tools/sandbox/src/test/java/org/opendaylight/nemo/tool/sandbox/models/NetworkTest.java new file mode 100644 index 0000000..b8b9032 --- /dev/null +++ b/nemo-tools/sandbox/src/test/java/org/opendaylight/nemo/tool/sandbox/models/NetworkTest.java @@ -0,0 +1,130 @@ +/* + * Copyright (c) 2016 Huawei, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.nemo.tool.sandbox.models; + +import junit.framework.TestCase; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import static org.mockito.Mockito.*; +import static org.junit.Assert.*; +import org.opendaylight.nemo.tool.sandbox.models.Cache; +import org.opendaylight.nemo.tool.sandbox.models.Connector; +import org.opendaylight.nemo.tool.sandbox.models.Network; + +import org.junit.runner.RunWith; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.api.support.membermodification.MemberMatcher; +import org.powermock.api.support.membermodification.MemberModifier; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; +import org.opendaylight.nemo.tool.sandbox.CmdExecutor; + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; +import org.opendaylight.nemo.tool.sandbox.CmdExecutor; +import org.opendaylight.nemo.tool.sandbox.utils.Config; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + + +/** + * Created by Thomas Liu on 2016/1/14. + */ +@RunWith(PowerMockRunner.class) +@PrepareForTest({CmdExecutor.class}) +public class NetworkTest extends TestCase { + private Network networkTest; + + @Before + public void setUp() throws Exception { + networkTest = new Network(); + + } + + @Test + public void testAddHost() throws Exception { + networkTest.addHost(new Cache("src1","1")); + networkTest.addHost(new Cache("dst2","1")); + } + + @Test + public void testAddSwitch() throws Exception { + networkTest.addSwitch(new Switch("dst1", 1L)); + networkTest.addSwitch(new Switch("src2", 1L)); + networkTest.addSwitch(new Switch("src3", 1L)); + networkTest.addSwitch(new Switch("dst3", 1L)); + } + + @Test + public void testAddLink() throws Exception { + networkTest.addLink(new Link(new Connector("src1", 1), new Connector("dst1", 2))); + networkTest.addLink(new Link(new Connector("src2", 1), new Connector("dst2", 2))); + networkTest.addLink(new Link(new Connector("src3", 1), new Connector("dst3", 2))); + + } + + @Test + public void testExecute() throws Exception { + PowerMockito.mockStatic(CmdExecutor.class); + PowerMockito.when(CmdExecutor.open()).thenReturn(true); + PowerMockito.when(CmdExecutor.sshExecute(any(String.class))).thenReturn("null"); + PowerMockito.doNothing().when(CmdExecutor.class); + CmdExecutor.close(); + Assert.assertNotNull(networkTest.execute("cache", "command")); + + } + + @Test + public void testInstall() throws Exception { + //test traversal + networkTest.install(); + + } + + @Test + public void testUninstall() throws Exception { + PowerMockito.mockStatic(CmdExecutor.class); + PowerMockito.when(CmdExecutor.sshExecute(any(String.class))).thenReturn("null"); + PowerMockito.when(CmdExecutor.sshExecute(any(String.class))).thenReturn("null"); + PowerMockito.when(CmdExecutor.sshExecute(any(String.class))).thenReturn("null"); + PowerMockito.when(CmdExecutor.sshExecute(any(String.class))).thenReturn("null"); + PowerMockito.when(CmdExecutor.sshExecute(any(String.class))).thenReturn("null"); + PowerMockito.when(CmdExecutor.sshExecute(any(String.class))).thenReturn("null"); + + networkTest.uninstall(); + + } + + @Test + public void testEchoConfig() throws Exception { + PowerMockito.mockStatic(CmdExecutor.class); + PowerMockito.when(CmdExecutor.sshExecute(any(String.class))).thenReturn("null"); + PowerMockito.when(CmdExecutor.sshExecute(any(String.class))).thenReturn("null"); + PowerMockito.when(CmdExecutor.sshExecute(any(String.class))).thenReturn("null"); + PowerMockito.when(CmdExecutor.sshExecute(any(String.class))).thenReturn("null"); + PowerMockito.when(CmdExecutor.sshExecute(any(String.class))).thenReturn("null"); + + networkTest.echoConfig(); + + //test hostJsonNode() + + + + } + + @Test + public void testInnerLinkJsonNode() throws Exception { + + Assert.assertNotNull(networkTest.innerLinkJsonNode()); + + + } +} \ No newline at end of file diff --git a/nemo-tools/sandbox/src/test/java/org/opendaylight/nemo/tool/sandbox/models/RouterTest.java b/nemo-tools/sandbox/src/test/java/org/opendaylight/nemo/tool/sandbox/models/RouterTest.java new file mode 100644 index 0000000..8326a78 --- /dev/null +++ b/nemo-tools/sandbox/src/test/java/org/opendaylight/nemo/tool/sandbox/models/RouterTest.java @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2016 Huawei, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.nemo.tool.sandbox.models; + +import junit.framework.TestCase; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import static org.mockito.Mockito.*; +import static org.junit.Assert.*; + +/** + * Created by Thomas Liu on 2016/1/14. + */ +public class RouterTest extends TestCase { + private String name; + private long dataPathId; + private Router routerTest; + @Before + public void setUp() throws Exception { + + } + + @Test + public void test1() throws Exception { + name = new String("name1"); + dataPathId = 1L; + routerTest = new Router(name,dataPathId); + } +} \ No newline at end of file diff --git a/nemo-tools/sandbox/src/test/java/org/opendaylight/nemo/tool/sandbox/models/SwitchTest.java b/nemo-tools/sandbox/src/test/java/org/opendaylight/nemo/tool/sandbox/models/SwitchTest.java new file mode 100644 index 0000000..d94055f --- /dev/null +++ b/nemo-tools/sandbox/src/test/java/org/opendaylight/nemo/tool/sandbox/models/SwitchTest.java @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2016 Huawei, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.nemo.tool.sandbox.models; + + +import junit.framework.TestCase; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import static org.mockito.Mockito.*; +import static org.junit.Assert.*; + +import org.opendaylight.nemo.tool.sandbox.utils.Config; +import org.opendaylight.nemo.tool.sandbox.utils.HexString; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import java.lang.reflect.Method; +import java.lang.reflect.Field; + +/** + * Created by Thomas Liu on 2016/1/14. + */ +public class SwitchTest extends TestCase { + + private String name; + private long dataPathId; + private Switch switchTest; + private Class class1; + private Method method; + + + @Before + public void setUp() throws Exception { + name = new String("name1"); + dataPathId = 1L; + switchTest = new Switch(name,dataPathId); + class1 = Switch.class; + org.opendaylight.nemo.tool.sandbox.models.Connector connector = new org.opendaylight.nemo.tool.sandbox.models.Connector("connectorname",1); + switchTest.addConnectors(connector); + } + + @Test + public void testGetDataPathId() throws Exception { + Assert.assertNotNull(switchTest.getDataPathId()); + } + + @Test + public void testGenerateCommands() throws Exception { + method = class1.getDeclaredMethod("generateCommands",new Class[]{}); + method.setAccessible(true); + Assert.assertNotNull(method.invoke(switchTest)); + + } + + @Test + public void testToString() throws Exception { + Assert.assertNotNull(switchTest.toString()); + + } +} \ No newline at end of file diff --git a/nemo-tools/sandbox/src/test/java/org/opendaylight/nemo/tool/sandbox/models/VirtualMachineTest.java b/nemo-tools/sandbox/src/test/java/org/opendaylight/nemo/tool/sandbox/models/VirtualMachineTest.java new file mode 100644 index 0000000..f405927 --- /dev/null +++ b/nemo-tools/sandbox/src/test/java/org/opendaylight/nemo/tool/sandbox/models/VirtualMachineTest.java @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2016 Huawei, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.nemo.tool.sandbox.models; + +import junit.framework.TestCase; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import static org.mockito.Mockito.*; +import static org.junit.Assert.*; + +import org.opendaylight.nemo.tool.sandbox.CmdExecutor; +import org.opendaylight.nemo.tool.sandbox.models.VirtualMachine; + +import java.lang.reflect.Method; +import java.lang.reflect.Field; + +import org.junit.runner.RunWith; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.api.support.membermodification.MemberMatcher; +import org.powermock.api.support.membermodification.MemberModifier; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; +import org.opendaylight.nemo.tool.sandbox.CmdExecutor; + +/** + * Created by Thomas Liu on 2016/1/14. + */ +@RunWith(PowerMockRunner.class) +@PrepareForTest({CmdExecutor.class}) +public class VirtualMachineTest extends TestCase { + String name,uuId; + Cache cacheTest; + private VirtualMachine virtualMachineTest; + private Connector connector; + private Class class1; + private Method method; + @Before + public void setUp() throws Exception { + name = new String("name1"); + uuId = new String("11111111-1111-1111-1111-111111111111"); + virtualMachineTest = new VirtualMachine(name,uuId); + org.opendaylight.nemo.tool.sandbox.models.Connector connector = mock(org.opendaylight.nemo.tool.sandbox.models.Connector.class); + virtualMachineTest.addConnectors(connector); + class1 = VirtualMachine.class; + + } + + @Test + public void testGenerateCommands() throws Exception { + method = class1.getDeclaredMethod("generateCommands",new Class[]{}); + method.setAccessible(true); + Assert.assertNotNull(method.invoke(virtualMachineTest)); + } + + @Test + public void testUninstall() throws Exception { + PowerMockito.mockStatic(CmdExecutor.class); + PowerMockito.when(CmdExecutor.sshExecute(any(String.class))).thenReturn("null"); + virtualMachineTest.uninstall(); + + } +} \ No newline at end of file diff --git a/nemo-tools/sandbox/src/test/java/org/opendaylight/nemo/tool/sandbox/northbound/CreateRequestTest.java b/nemo-tools/sandbox/src/test/java/org/opendaylight/nemo/tool/sandbox/northbound/CreateRequestTest.java new file mode 100644 index 0000000..d95bbd0 --- /dev/null +++ b/nemo-tools/sandbox/src/test/java/org/opendaylight/nemo/tool/sandbox/northbound/CreateRequestTest.java @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2016 Huawei, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.nemo.tool.sandbox.northbound; + +import junit.framework.TestCase; +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.*; + +/** + * Created by zhangmeng on 2016/1/14. + */ +public class CreateRequestTest extends TestCase { + private CreateRequest createRequest; + @Before + public void setUp() throws Exception { + + } + + @Test + public void testInit()throws Exception{ + createRequest = new CreateRequest(); + } +} \ No newline at end of file diff --git a/nemo-tools/sandbox/src/test/java/org/opendaylight/nemo/tool/sandbox/northbound/ExecuteRequestTest.java b/nemo-tools/sandbox/src/test/java/org/opendaylight/nemo/tool/sandbox/northbound/ExecuteRequestTest.java new file mode 100644 index 0000000..35d9a50 --- /dev/null +++ b/nemo-tools/sandbox/src/test/java/org/opendaylight/nemo/tool/sandbox/northbound/ExecuteRequestTest.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2016 Huawei, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.nemo.tool.sandbox.northbound; + +import junit.framework.TestCase; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.*; + +/** + * Created by zhangmeng on 2016/1/14. + */ +public class ExecuteRequestTest extends TestCase { + private ExecuteRequest executeRequest; + @Before + public void setUp() throws Exception { + executeRequest = new ExecuteRequest(); + } + + @Test + public void testGet_Set() throws Exception { + Assert.assertTrue(executeRequest.getHostName() == null); + executeRequest.setHostName("test"); + Assert.assertTrue(executeRequest.getHostName().equals("test")); + + Assert.assertTrue(executeRequest.getCommand() == null); + executeRequest.setCommand("command"); + Assert.assertTrue(executeRequest.getCommand().equals("command")); + + //test to string + Assert.assertTrue(executeRequest.toString().equals("ExecuteRequest{" + + "hostName='" + "test" + '\'' + + ", command='" + "command" + '\'' + + '}')); + } + +} \ No newline at end of file diff --git a/nemo-tools/sandbox/src/test/java/org/opendaylight/nemo/tool/sandbox/northbound/RestServerTest.java b/nemo-tools/sandbox/src/test/java/org/opendaylight/nemo/tool/sandbox/northbound/RestServerTest.java new file mode 100644 index 0000000..25e6c4c --- /dev/null +++ b/nemo-tools/sandbox/src/test/java/org/opendaylight/nemo/tool/sandbox/northbound/RestServerTest.java @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2016 Huawei, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.nemo.tool.sandbox.northbound; + +import junit.framework.TestCase; +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.*; +import org.glassfish.grizzly.http.server.HttpServer; +import org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory; +import org.glassfish.jersey.server.ResourceConfig; + +import java.io.Reader; +import java.net.URI; +/** + * Created by zhangmeng on 2016/1/14. + */ +public class RestServerTest extends TestCase { + private RestServer restServer; + @Before + public void setUp() throws Exception { + restServer = new RestServer(); + } + + @Test + public void testStart() throws Exception { +// RestServer.start("s1"); + } + + @Test + public void testStop() throws Exception { + RestServer.stop(); + } +} \ No newline at end of file diff --git a/nemo-tools/sandbox/src/test/java/org/opendaylight/nemo/tool/sandbox/northbound/SandboxNorthboundTest.java b/nemo-tools/sandbox/src/test/java/org/opendaylight/nemo/tool/sandbox/northbound/SandboxNorthboundTest.java new file mode 100644 index 0000000..d15f0cb --- /dev/null +++ b/nemo-tools/sandbox/src/test/java/org/opendaylight/nemo/tool/sandbox/northbound/SandboxNorthboundTest.java @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2016 Huawei, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.nemo.tool.sandbox.northbound; + +import junit.framework.TestCase; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.*; +import org.codehaus.enunciate.jaxrs.ResponseCode; +import org.codehaus.enunciate.jaxrs.StatusCodes; +import org.codehaus.enunciate.jaxrs.TypeHint; +import org.junit.runner.RunWith; +import org.opendaylight.nemo.tool.sandbox.SandBoxManager; + +import javax.ws.rs.*; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.UriInfo; +import java.util.ArrayList; +import java.util.List; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.api.support.membermodification.MemberMatcher; +import org.powermock.api.support.membermodification.MemberModifier; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; +import static org.mockito.Mockito.*; +/** + * Created by zhangmeng on 2016/1/14. + */ + +public class SandboxNorthboundTest extends TestCase { + private SandboxNorthbound sandboxNorthbound; + @Before + public void setUp() throws Exception { + sandboxNorthbound = new SandboxNorthbound(); + } + + @Test + public void testCreate() throws Exception { + ExecuteRequest executeRequest = new ExecuteRequest(); + Assert.assertTrue(sandboxNorthbound.create(null,"test") != null); + Assert.assertTrue(sandboxNorthbound.create(null,executeRequest) != null); + } + + @Test + public void testDestroy() throws Exception { + Assert.assertTrue(sandboxNorthbound.destroy(null) != null); + } + + @Test + public void testGetXml() throws Exception { + Assert.assertTrue(sandboxNorthbound.getXml() != null); + } + + @Test + public void testGetHosts() throws Exception { + Assert.assertTrue(sandboxNorthbound.getHosts() == null); + } + + @Test + public void testGetSwitches() throws Exception { + Assert.assertTrue(sandboxNorthbound.getSwitches() != null); + } + + @Test + public void testGetLinks() throws Exception { + Assert.assertTrue(sandboxNorthbound.getLinks() != null); + } + + @Test + public void testGetExternals() throws Exception { + Assert.assertTrue(sandboxNorthbound.getExternals() == null); + } +} \ No newline at end of file diff --git a/nemo-tools/sandbox/src/test/java/org/opendaylight/nemo/tool/sandbox/utils/ConfigTest.java b/nemo-tools/sandbox/src/test/java/org/opendaylight/nemo/tool/sandbox/utils/ConfigTest.java new file mode 100644 index 0000000..4d665b9 --- /dev/null +++ b/nemo-tools/sandbox/src/test/java/org/opendaylight/nemo/tool/sandbox/utils/ConfigTest.java @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2015 Huawei, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.nemo.tool.sandbox.utils; + +import junit.framework.TestCase; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.*; + +/** + * Created by zhangmeng on 2016/1/14. + */ +public class ConfigTest extends TestCase { + private Config config; + @Before + public void setUp() throws Exception { + config = new Config(); + } + + @Test + public void testAll() throws Exception{ + Assert.assertTrue(Config.getControllerSocket() != null); + Assert.assertTrue(Config.isPrintProcess() == false); + Assert.assertTrue(Config.getHostName() != null); + Assert.assertTrue(Config.getHostUser() != null); + Assert.assertTrue(Config.getHostPassword() != null); + Assert.assertTrue(Config.getConfigPath() != null); + Assert.assertTrue(Config.getConfigHostsFileName() != null); + Assert.assertTrue(Config.getConfigExternalsFileName() != null); + Assert.assertTrue(Config.getConfigLinksFileName() != null); + Assert.assertTrue(Config.getConfigNodesFileName() != null); + } +} \ No newline at end of file diff --git a/nemo-tools/sandbox/src/test/java/org/opendaylight/nemo/tool/sandbox/utils/FileUtilsTest.java b/nemo-tools/sandbox/src/test/java/org/opendaylight/nemo/tool/sandbox/utils/FileUtilsTest.java new file mode 100644 index 0000000..5030142 --- /dev/null +++ b/nemo-tools/sandbox/src/test/java/org/opendaylight/nemo/tool/sandbox/utils/FileUtilsTest.java @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2015 Huawei, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.nemo.tool.sandbox.utils; + +import junit.framework.TestCase; +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.*; + +/** + * Created by zhangmeng on 2016/1/14. + */ +public class FileUtilsTest extends TestCase { + private FileUtils fileUtils; + @Before + public void setUp() throws Exception { + fileUtils = new FileUtils(); + } + + @Test + public void testWrite() throws Exception { + FileUtils.write("home","test"); + } +} \ No newline at end of file diff --git a/nemo-tools/sandbox/src/test/java/org/opendaylight/nemo/tool/sandbox/utils/HexStringTest.java b/nemo-tools/sandbox/src/test/java/org/opendaylight/nemo/tool/sandbox/utils/HexStringTest.java new file mode 100644 index 0000000..7c7bf7d --- /dev/null +++ b/nemo-tools/sandbox/src/test/java/org/opendaylight/nemo/tool/sandbox/utils/HexStringTest.java @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2015 Huawei, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.nemo.tool.sandbox.utils; + +import junit.framework.TestCase; +import org.junit.Assert; +import org.junit.Test; + +import static org.junit.Assert.*; + +/** + * Created by zhangmeng on 2016/1/14. + */ +public class HexStringTest extends TestCase { + private HexString hexString; + @Test + public void testToHexString() throws Exception { + Assert.assertTrue(HexString.toHexString(1L,6) != null); + Assert.assertTrue(HexString.toHexString(1L) != null); + } + + @Test + public void testFromHexString() throws Exception { + Assert.assertTrue(HexString.fromHexString("22:32") != null); + } + + @Test + public void testToLong() throws Exception { +// System.out.println(HexString.toLong("11:22")); + Assert.assertTrue(HexString.toLong("11:22") != 0); + } +} \ No newline at end of file diff --git a/nemo-tools/sandbox/src/test/java/org/opendaylight/nemo/tool/sandbox/utils/PropertyLoaderTest.java b/nemo-tools/sandbox/src/test/java/org/opendaylight/nemo/tool/sandbox/utils/PropertyLoaderTest.java new file mode 100644 index 0000000..281ad43 --- /dev/null +++ b/nemo-tools/sandbox/src/test/java/org/opendaylight/nemo/tool/sandbox/utils/PropertyLoaderTest.java @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2015 Huawei, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.nemo.tool.sandbox.utils; + +import junit.framework.TestCase; +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.*; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.List; +/** + * Created by zhangmeng on 2016/1/14. + */ +public class PropertyLoaderTest extends TestCase { + private PropertyLoader propertyLoader; + @Before + public void setUp() throws Exception { + propertyLoader = new PropertyLoader(); + } + + @Test + public void testLoadProperties() throws Exception { + PropertyLoader.loadProperties("home","no file!"); + } + + @Test + public void testReadLines() throws Exception { + PropertyLoader.readLines("home","no file!"); + } +} \ No newline at end of file