Examples of EthernetAddress


Examples of com.fasterxml.uuid.EthernetAddress

public class UUIDIdentifierGenerator implements IdentifierGenerator<String> {

  private TimeBasedGenerator generator;

  public UUIDIdentifierGenerator() {
    final EthernetAddress address = EthernetAddress.fromInterface();
    generator = Generators.timeBasedGenerator(address);
  }
View Full Code Here

Examples of com.fasterxml.uuid.EthernetAddress

        // dummy ethernet addresses
        // NOTE: although creating a bunch of dummy ethernet addresses
        // is not the normal mode of operation, we'return testing for
        // generally good behavior, so we'll create a bunch to make sure the
        // general patterns are observed
        EthernetAddress ethernet_address_array[] =
            new EthernetAddress[SIZE_OF_TEST_ARRAY];
       
        // now create the array of uuids
        Random rnd = new Random(123L);
        for (int i = 0; i < ethernet_address_array.length; i++) {
            ethernet_address_array[i] = EthernetAddress.constructMulticastAddress(rnd);
        }
       
        EthernetAddress null_ethernet_address = new EthernetAddress(0L);
        for (int i = 0; i < ethernet_address_array.length; i++)
        {
            byte[] ethernet_address = ethernet_address_array[i].asByteArray();
            // check that none of the EthernetAddresses are null
            assertFalse("dummy EthernetAddress was null",
                    Arrays.equals(null_ethernet_address.asByteArray(),
                                ethernet_address));
           
            // check that the "broadcast" bit is set in the created address
            /* 08-Feb-2004, TSa: Fixed as per fix to actual code; apparently
             *   broadcast bit is LSB, not MSB.
View Full Code Here

Examples of com.fasterxml.uuid.EthernetAddress

     */
    public void testGenerateTimeBasedUUIDWithEthernetAddress()
    {
        // this test will attempt to check for reasonable behavior of the
        // generateTimeBasedUUID(EthernetAddress) method
        EthernetAddress ethernet_address =
            new EthernetAddress("87:F5:93:06:D3:0C");
       
        // we need a instance to use
        TimeBasedGenerator uuid_gen = Generators.timeBasedGenerator(ethernet_address);
       
        // check that given a number of calls to generateTimeBasedUUID,
View Full Code Here

Examples of com.fasterxml.uuid.EthernetAddress

        // lets test some error cases
        // first, passing null
        try
        {
            /*EthernetAddress ethernet_address =*/
                new EthernetAddress((byte[])null);
            // if we reached here we failed because we didn't get an exception
            fail("Expected exception not caught");
        }
        catch (NullPointerException ex)
        {
            // this is the success case so do nothing
        }
        catch (Exception ex)
        {
            fail("Caught unexpected exception: " + ex);
        }
       
        // now an array that is too small
        try
        {
            /*EthernetAddress ethernet_address =*/
                new EthernetAddress(
                    new byte[ETHERNET_ADDRESS_ARRAY_LENGTH - 1]);
            // if we reached here we failed because we didn't get an exception
            fail("Expected exception not caught");
        }
        catch (NumberFormatException ex)
        {
            // this is the success case so do nothing
        }
        catch (Exception ex)
        {
            fail("Caught unexpected exception: " + ex);
        }

        // now an array that is too big
        try {
            /*EthernetAddress ethernet_address =*/
                new EthernetAddress(
                    new byte[ETHERNET_ADDRESS_ARRAY_LENGTH + 1]);
            // if we reached here we failed because we didn't get an exception
            fail("Expected exception not caught");
        } catch (NumberFormatException ex) {
            // this is the success case so do nothing
        } catch (Exception ex) {
            fail("Caught unexpected exception: " + ex);
        }

        // let's test that creating a EthernetAddress from an zero'd array
        // gives us a null EthernetAddress (definition of null EthernetAddress)
        EthernetAddress ethernet_address =
            new EthernetAddress(new byte[ETHERNET_ADDRESS_ARRAY_LENGTH]);
        assertEquals(
            "EthernetAddress(byte[]) did not create expected EthernetAddress",
            NULL_ETHERNET_ADDRESS_LONG,
            ethernet_address.toLong());
       
        // let's test creating an array from a good byte array
        ethernet_address =
            new EthernetAddress(VALID_ETHERNET_ADDRESS_BYTE_ARRAY);
        assertEquals(
            "EthernetAddress(byte[]) did not create expected EthernetAddress",
            VALID_ETHERNET_ADDRESS_LONG,
            ethernet_address.toLong());
    }
View Full Code Here

Examples of com.fasterxml.uuid.EthernetAddress

     */
    public void testLongEthernetAddressConstructor()
    {
        // let's test that creating a EthernetAddress from an zero long
        // gives us a null EthernetAddress (definition of null EthernetAddress)
        EthernetAddress ethernet_address =
            new EthernetAddress(0x0000000000000000L);
        assertEquals(
            "EthernetAddress(long) did not create expected EthernetAddress",
            NULL_ETHERNET_ADDRESS_LONG,
            ethernet_address.toLong());
       
        // let's test creating an array from a good long
        ethernet_address = new EthernetAddress(VALID_ETHERNET_ADDRESS_LONG);
        assertEquals(
            "EthernetAddress(long) did not create expected EthernetAddress",
            VALID_ETHERNET_ADDRESS_LONG,
            ethernet_address.toLong());
    }
View Full Code Here

Examples of com.fasterxml.uuid.EthernetAddress

    {
        // test a null string case
        try
        {
            /*EthernetAddress ethernet_address =*/
                new EthernetAddress((String)null);
            fail("Expected exception not caught");
        }
        catch (NullPointerException ex)
        {
            // this is the success case so do nothing
View Full Code Here

Examples of com.fasterxml.uuid.EthernetAddress

    {
        // we'll test making a couple EthernetAddresses and then check that
        // asByteArray returns the same value in long form as used to create it
       
        // first we'll test the null EthernetAddress
        EthernetAddress ethernet_address = new EthernetAddress(0L);
        assertEquals("Expected length of returned array wrong",
            ETHERNET_ADDRESS_ARRAY_LENGTH,
            ethernet_address.asByteArray().length);
        assertEthernetAddressArraysAreEqual(
            NULL_ETHERNET_ADDRESS_BYTE_ARRAY, 0,
            ethernet_address.asByteArray(), 0);
       
        // now test a non-null EthernetAddress
        ethernet_address = new EthernetAddress(VALID_ETHERNET_ADDRESS_LONG);
        assertEquals("Expected length of returned array wrong",
            ETHERNET_ADDRESS_ARRAY_LENGTH,
            ethernet_address.asByteArray().length);
        assertEthernetAddressArraysAreEqual(
            VALID_ETHERNET_ADDRESS_BYTE_ARRAY, 0,
            ethernet_address.asByteArray(), 0);
       
        // let's make sure that changing the returned array doesn't mess with
        // the wrapped EthernetAddress's internals
        byte[] ethernet_address_byte_array = ethernet_address.asByteArray();
        // we'll just stir it up a bit and then check that the original
        // EthernetAddress was not changed in the process.
        // The easiest stir is to sort it ;)
        Arrays.sort(ethernet_address_byte_array);
        assertEthernetAddressArraysAreNotEqual(
            VALID_ETHERNET_ADDRESS_BYTE_ARRAY, 0,
            ethernet_address_byte_array, 0);
        assertEthernetAddressArraysAreNotEqual(
            ethernet_address.asByteArray(), 0,
            ethernet_address_byte_array, 0);
        assertEthernetAddressArraysAreEqual(
            VALID_ETHERNET_ADDRESS_BYTE_ARRAY, 0,
            ethernet_address.asByteArray(), 0);
    }
View Full Code Here

Examples of com.fasterxml.uuid.EthernetAddress

        // x.clone().equals(x)
        // will be true, this is not an absolute requirement.
        // For EthernetAddress, this test will check that all the above
        // ARE true in the case of EthernetAddress clone() because it is
        // the desired behavior.
        EthernetAddress x = new EthernetAddress(VALID_ETHERNET_ADDRESS_STRING);
        assertTrue("x.clone() != x did not return true",
                    x.clone() != x);
        assertTrue("x.clone().getClass() == x.getClass() did not return true",
                    x.clone().getClass() == x.getClass());
        assertTrue("x.clone().equals(x) did not return true",
                    x.clone().equals(x));
    }
View Full Code Here

Examples of com.fasterxml.uuid.EthernetAddress

        }
       
        // now we'll test some simple base cases
        // 2 null EthernetAddresses always compare to 0
        assertEthernetAddressEqualOrderHelper(NULL_ETHERNET_ADDRESS,
            new EthernetAddress(0L));
       
        // 2 of the same value EthernetAddresses are always 0
        assertEthernetAddressEqualOrderHelper(MAC0_ETHERNET_ADDRESS,
            new EthernetAddress(MAC0_ETHERNET_ADDRESS.toLong()));
       
        // the 'null EthernetAddress' always comes first in the ordering
        assertEthernetAddressGreaterOrderHelper(MAC0_ETHERNET_ADDRESS,
            NULL_ETHERNET_ADDRESS);
       
        // EthernetAddresses will always sort
        // with the 'numerically' greater MAC addresses coming later
        assertEthernetAddressGreaterOrderHelper(MAC4_ETHERNET_ADDRESS,
                                                MAC0_ETHERNET_ADDRESS);       
        assertEthernetAddressGreaterOrderHelper(MAC9_ETHERNET_ADDRESS,
                                                MAC4_ETHERNET_ADDRESS);
        assertEthernetAddressGreaterOrderHelper(MAC9_ETHERNET_ADDRESS,
                                                MAC0_ETHERNET_ADDRESS);
       
        // now we will test a bigger case of the compareTo functionality
        // of the EthernetAddress class
        // easiest way to do this is to create an array of EthernetAddresses
        // and sort it then test that this array is in the expected order
       
        // before sort, the array contains (in psudo-random order)
        // 15 EthernetAddresses of this distribution:
        // 1 - null EthernetAddress
        // 2 - mac0
        // 1 - mac1
        // 1 - mac2
        // 2 - mac3
        // 2 - mac4
        // 2 - mac5
        // 1 - mac6
        // 1 - mac7
        // 1 - mac8
        // 1 - mac9
        EthernetAddress ethernet_address_array[] = new EthernetAddress[15];
        ethernet_address_array[0] = MAC4_ETHERNET_ADDRESS;
        ethernet_address_array[1] = MAC6_ETHERNET_ADDRESS;
        ethernet_address_array[2] = MAC0_ETHERNET_ADDRESS;
        ethernet_address_array[3] = MAC5_ETHERNET_ADDRESS;
        ethernet_address_array[4] = MAC3_ETHERNET_ADDRESS;
View Full Code Here

Examples of com.fasterxml.uuid.EthernetAddress

     */
    public void testEquals()
    {
        // test passing null to equals returns false
        // (as specified in the JDK docs for Object)
        EthernetAddress x =
            new EthernetAddress(VALID_ETHERNET_ADDRESS_BYTE_ARRAY);
        assertFalse("equals(null) didn't return false",
                x.equals((Object)null));
       
        // test passing an object which is not a EthernetAddress returns false
        assertFalse("x.equals(non_EthernetAddress_object) didn't return false",
                    x.equals(new Object()));
       
        // test a case where two EthernetAddresss are definitly not equal
        EthernetAddress w =
            new EthernetAddress(ANOTHER_VALID_ETHERNET_ADDRESS_BYTE_ARRAY);
        assertFalse("x == w didn't return false",
                    x == w);
        assertFalse("x.equals(w) didn't return false",
                    x.equals(w));

        // test refelexivity
        assertTrue("x.equals(x) didn't return true",
                    x.equals(x));
       
        // test symmetry
        EthernetAddress y =
            new EthernetAddress(VALID_ETHERNET_ADDRESS_BYTE_ARRAY);
        assertFalse("x == y didn't return false",
                    x == y);
        assertTrue("y.equals(x) didn't return true",
                    y.equals(x));
        assertTrue("x.equals(y) didn't return true",
                    x.equals(y));
       
        // now we'll test transitivity
        EthernetAddress z =
            new EthernetAddress(VALID_ETHERNET_ADDRESS_BYTE_ARRAY);
        assertFalse("x == y didn't return false",
                    x == y);
        assertFalse("x == y didn't return false",
                    y == z);
        assertFalse("x == y didn't return false",
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.