text:
package org.apache.catalina.tribes.io;

import java.sql.Timestamp;
import java.util.Arrays;

import org.apache.catalina.tribes.Channel;
import org.apache.catalina.tribes.ChannelMessage;
import org.apache.catalina.tribes.Member;
import org.apache.catalina.tribes.membership.MemberImpl;
import org.apache.catalina.tribes.util.UUIDGenerator;

/**
 * The ChannelData object is used to transfer a message through the
 * channel interceptor stack and eventually out on a transport to be sent
 * to another node. While the message is being processed by the different
 * interceptors, the message data can be manipulated as each interceptor seems appropriate.
 * @author Peter Rossbach
 * @author Filip Hanik
 * @version $Id: ChannelData.java 1096243 2011-04-23 21:53:00Z markt $
 *
 */
public class ChannelData implements ChannelMessage {
    private static final long serialVersionUID = 1L;

    public static final ChannelData[] EMPTY_DATA_ARRAY = new ChannelData[0];

    public static volatile boolean USE_SECURE_RANDOM_FOR_UUID = false;

    /**
     * The options this message was sent with
     */
    private int options = 0 ;
    /**
     * The message data, stored in a dynamic buffer
     */
    private XByteBuffer message ;
    /**
     * The timestamp that goes with this message
     */
    private long timestamp ;
    /**
     * A unique message id
     */
    private byte[] uniqueId ;
    /**
     * The source or reply-to address for this message
     */
    private Member address;

    /**
     * Creates an empty channel data with a new unique Id
     * @see #ChannelData(boolean)
     */
    public ChannelData() {
        this(true);
    }

    /**
     * Create an empty channel data object
     * @param generateUUID boolean - if true, a unique Id will be generated
     */
    public ChannelData(boolean generateUUID) {
        if ( generateUUID ) generateUUID();
    }

    /**
     * Creates a new channel data object with data
     * @param uniqueId - unique message id
     * @param message - message data
     * @param timestamp - message timestamp
     */
    public ChannelData(byte[] uniqueId, XByteBuffer message, long timestamp) {
        this.uniqueId = uniqueId;
        this.message = message;
        this.timestamp = timestamp;
    }

    /**
     * @return Returns the message byte buffer
     */
    @Override
    public XByteBuffer getMessage() {
        return message;
    }
    /**
     * @param message The message to send.
     */
    @Override
    public void setMessage(XByteBuffer message) {
        this.message = message;
    }
    /**
     * @return Returns the timestamp.
     */
    @Override
    public long getTimestamp() {
        return timestamp;
    }
    /**
     * @param timestamp The timestamp to send
     */
    @Override
    public void setTimestamp(long timestamp) {
        this.timestamp = timestamp;
    }
    /**
     * @return Returns the uniqueId.
     */
    @Override
    public byte[] getUniqueId() {
        return uniqueId;
    }
    /**
     * @param uniqueId The uniqueId to send.
     */
    public void setUniqueId(byte[] uniqueId) {
        this.uniqueId = uniqueId;
    }
    /**
     * @return returns the message options
     * see org.apache.catalina.tribes.Channel#sendMessage(org.apache.catalina.tribes.Member[], java.io.Serializable, int)
     *
     */
    @Override
    public int getOptions() {
        return options;
    }
    /**
     * Sets the message options.
     *
     * @param options the message options
     */
    @Override
    public void setOptions(int options) {
        this.options = options;
    }

    /**
     * Returns the source or reply-to address
     * @return Member
     */
    @Override
    public Member getAddress() {
        return address;
    }

    /**
     * Sets the source or reply-to address
     * @param address Member
     */
    @Override
    public void setAddress(Member address) {
        this.address = address;
    }

    /**
     * Generates a UUID and invokes setUniqueId
     */
    public void generateUUID() {
        byte[] data = new byte[16];
        UUIDGenerator.randomUUID(USE_SECURE_RANDOM_FOR_UUID,data,0);
        setUniqueId(data);
    }

    public int getDataPackageLength() {
        int length =
            4 + //options
            8 + //timestamp  off=4
            4 + //unique id length off=12
            uniqueId.length+ //id data off=12+uniqueId.length
            4 + //addr length off=12+uniqueId.length+4
            ((MemberImpl)address).getDataLength()+ //member data off=12+uniqueId.length+4+add.length
            4 + //message length off=12+uniqueId.length+4+add.length+4
            message.getLength();
        return length;

    }

    /**
     * Serializes the ChannelData object into a byte[] array
     * @return byte[]
     */
    public byte[] getDataPackage()  {
        int length = getDataPackageLength();
        byte[] data = new byte[length];
        int offset = 0;
        return getDataPackage(data,offset);
    }

    public byte[] getDataPackage(byte[] data, int offset)  {
        byte[] addr = ((MemberImpl)address).getData(false);
        XByteBuffer.toBytes(options,data,offset);
        offset += 4; //options
        XByteBuffer.toBytes(timestamp,data,offset);
        offset += 8; //timestamp
        XByteBuffer.toBytes(uniqueId.length,data,offset);
        offset += 4; //uniqueId.length
        System.arraycopy(uniqueId,0,data,offset,uniqueId.length);
        offset += uniqueId.length; //uniqueId data
        XByteBuffer.toBytes(addr.length,data,offset);
        offset += 4; //addr.length
        System.arraycopy(addr,0,data,offset,addr.length);
        offset += addr.length; //addr data
        XByteBuffer.toBytes(message.getLength(),data,offset);
        offset += 4; //message.length
        System.arraycopy(message.getBytesDirect(),0,data,offset,message.getLength());
        offset += message.getLength(); //message data
        return data;
    }

    /**
     * Deserializes a ChannelData object from a byte array
     * @param xbuf byte[]
     * @return ChannelData
     */
    public static ChannelData getDataFromPackage(XByteBuffer xbuf)  {
        ChannelData data = new ChannelData(false);
        int offset = 0;
        data.setOptions(XByteBuffer.toInt(xbuf.getBytesDirect(),offset));
        offset += 4; //options
        data.setTimestamp(XByteBuffer.toLong(xbuf.getBytesDirect(),offset));
        offset += 8; //timestamp
        data.uniqueId = new byte[XByteBuffer.toInt(xbuf.getBytesDirect(),offset)];
        offset += 4; //uniqueId length
        System.arraycopy(xbuf.getBytesDirect(),offset,data.uniqueId,0,data.uniqueId.length);
        offset += data.uniqueId.length; //uniqueId data
        //byte[] addr = new byte[XByteBuffer.toInt(xbuf.getBytesDirect(),offset)];
        int addrlen = XByteBuffer.toInt(xbuf.getBytesDirect(),offset);
        offset += 4; //addr length
        //System.arraycopy(xbuf.getBytesDirect(),offset,addr,0,addr.length);
        data.setAddress(MemberImpl.getMember(xbuf.getBytesDirect(),offset,addrlen));
        //offset += addr.length; //addr data
        offset += addrlen;
        int xsize = XByteBuffer.toInt(xbuf.getBytesDirect(),offset);
        offset += 4; //xsize length
        System.arraycopy(xbuf.getBytesDirect(),offset,xbuf.getBytesDirect(),0,xsize);
        xbuf.setLength(xsize);
        data.message = xbuf;
        return data;

    }

    public static ChannelData getDataFromPackage(byte[] b)  {
        ChannelData data = new ChannelData(false);
        int offset = 0;
        data.setOptions(XByteBuffer.toInt(b,offset));
        offset += 4; //options
        data.setTimestamp(XByteBuffer.toLong(b,offset));
        offset += 8; //timestamp
        data.uniqueId = new byte[XByteBuffer.toInt(b,offset)];
        offset += 4; //uniqueId length
        System.arraycopy(b,offset,data.uniqueId,0,data.uniqueId.length);
        offset += data.uniqueId.length; //uniqueId data
        byte[] addr = new byte[XByteBuffer.toInt(b,offset)];
        offset += 4; //addr length
        System.arraycopy(b,offset,addr,0,addr.length);
        data.setAddress(MemberImpl.getMember(addr));
        offset += addr.length; //addr data
        int xsize = XByteBuffer.toInt(b,offset);
        //data.message = new XByteBuffer(new byte[xsize],false);
        data.message = BufferPool.getBufferPool().getBuffer(xsize,false);
        offset += 4; //message length
        System.arraycopy(b,offset,data.message.getBytesDirect(),0,xsize);
        data.message.append(b,offset,xsize);
        offset += xsize; //message data
        return data;
    }

    @Override
    public int hashCode() {
        return XByteBuffer.toInt(getUniqueId(),0);
    }

    /**
     * Compares to ChannelData objects, only compares on getUniqueId().equals(o.getUniqueId())
     * @param o Object
     * @return boolean
     */
    @Override
    public boolean equals(Object o) {
        if ( o instanceof ChannelData ) {
            return Arrays.equals(getUniqueId(),((ChannelData)o).getUniqueId());
        } else return false;
    }

    /**
     * Create a shallow clone, only the data gets recreated
     * @return ClusterData
     */
    @Override
    public Object clone() {
//        byte[] d = this.getDataPackage();
//        return ClusterData.getDataFromPackage(d);
        ChannelData clone = new ChannelData(false);
        clone.options = this.options;
        clone.message = new XByteBuffer(this.message.getBytesDirect(),false);
        clone.timestamp = this.timestamp;
        clone.uniqueId = this.uniqueId;
        clone.address = this.address;
        return clone;
    }

    /**
     * Complete clone
     * @return ClusterData
     */
    @Override
    public Object deepclone() {
        byte[] d = this.getDataPackage();
        return ChannelData.getDataFromPackage(d);
    }

    /**
     * Utility method, returns true if the options flag indicates that an ack
     * is to be sent after the message has been received and processed
     * @param options int - the options for the message
     * @return boolean
     * @see org.apache.catalina.tribes.Channel#SEND_OPTIONS_USE_ACK
     * @see org.apache.catalina.tribes.Channel#SEND_OPTIONS_SYNCHRONIZED_ACK
     */
    public static boolean sendAckSync(int options) {
        return ( (Channel.SEND_OPTIONS_USE_ACK & options) == Channel.SEND_OPTIONS_USE_ACK) &&
            ( (Channel.SEND_OPTIONS_SYNCHRONIZED_ACK & options) == Channel.SEND_OPTIONS_SYNCHRONIZED_ACK);
    }

    /**
     * Utility method, returns true if the options flag indicates that an ack
     * is to be sent after the message has been received but not yet processed
     * @param options int - the options for the message
     * @return boolean
     * @see org.apache.catalina.tribes.Channel#SEND_OPTIONS_USE_ACK
     * @see org.apache.catalina.tribes.Channel#SEND_OPTIONS_SYNCHRONIZED_ACK
     */
    public static boolean sendAckAsync(int options) {
        return ( (Channel.SEND_OPTIONS_USE_ACK & options) == Channel.SEND_OPTIONS_USE_ACK) &&
            ( (Channel.SEND_OPTIONS_SYNCHRONIZED_ACK & options) != Channel.SEND_OPTIONS_SYNCHRONIZED_ACK);
    }

    @Override
    public String toString() {
        StringBuilder buf = new StringBuilder();
        buf.append("ClusterData[src=");
        buf.append(getAddress()).append("; id=");
        buf.append(bToS(getUniqueId())).append("; sent=");
        buf.append(new Timestamp(this.getTimestamp()).toString()).append("]");
        return buf.toString();
    }

    public static String bToS(byte[] data) {
        StringBuilder buf = new StringBuilder(4*16);
        buf.append("{");
        for (int i=0; data!=null && i<data.length; i++ ) buf.append(String.valueOf(data[i])).append(" ");
        buf.append("}");
        return buf.toString();
    }

}


text:
/***************************************************************************
    DrawBrdg.cpp    Scott Randolph
    July 29, 1997

    Derived class to do special position and containment processing for
 bridges (platforms upon which ground vehicles can drive).
***************************************************************************/

#include "RViewPnt.h"
#include "RenderOW.h"
#include "DrawGrnd.h"
#include "DrawBrdg.h"

#ifdef USE_SH_POOLS
MEM_POOL DrawableBridge::pool;
#endif

/***************************************************************************
    Initialize a container for a BSP object to be drawn
***************************************************************************/
DrawableBridge::DrawableBridge(float s)
    : DrawableObject(s)
{
    drawClassID = Bridge;

    // Set this object's height to sea level to ensure we're in the lowest object list
    position.z = 0.0f;
    previousLOD = -1;

    // Start with no included area -- area will be added as segments are added.
    radius = 0.0f;
    InclusionRadiusSquared = 0.0f;
    maxX = maxY = -1e24f;
    minX = minY =  1e24f;

    // Fill in our callback request structures for when we get added to a parent list
    updateCBstruct.fn = UpdateMetrics;
    updateCBstruct.self = this;
    updateCBstruct.next = NULL;
    updateCBstruct.prev = NULL;
    sortCBstruct.fn = SortForViewpoint;
    sortCBstruct.self = this;
    sortCBstruct.next = NULL;
    sortCBstruct.prev = NULL;

    // Setup the contained object lists
    roadbedObjects.Setup();
    dynamicObjects.Setup();
}

/***************************************************************************
    Remove an instance of a brige object.
 All the children must be removed before this happens.  The dynamic
 children are handled when SetParentList( NULL ) happens upon removal
 of this object from the display list.  The static objects must be
 manually removed before this point.
***************************************************************************/
DrawableBridge::~DrawableBridge(void)
{
    ShiAssert(parentList == NULL);

    // Mark this object as finished (no area contained)
    InclusionRadiusSquared = -1.0f;

    // Clean up our list (must be empty at this point)
    roadbedObjects.Cleanup();
    dynamicObjects.Cleanup();
}

/***************************************************************************
    Add a segment (both under and over parts) to the bridge.
***************************************************************************/
void DrawableBridge::AddSegment(DrawableRoadbed *piece)
{
    Tpoint max, min;

    ShiAssert(piece);

    min.x = min.z = -(max.x = max.z = piece->Radius());

    // Update our center point and inclusion radius
    maxX = max(maxX, max.z + piece->position.x);
    minX = min(minX, min.z + piece->position.x);
    maxY = max(maxY, max.x + piece->position.y);
    minY = min(minY, min.x + piece->position.y);

    position.x = (maxX + minX) * 0.5f;
    position.y = (maxY + minY) * 0.5f;

    InclusionRadiusSquared = (maxX - position.x) * (maxX - position.x) +
                                (maxY - position.y) * (maxY - position.y);
    radius = (float)sqrt(InclusionRadiusSquared);

    // Add the two drawable pieces of this new segment
    roadbedObjects.InsertObject(piece);
}

/***************************************************************************
    Replace a piece of a bridge (used for damage, etc.)
 Note that this will, in fact, replace ANY drawable object in ANY list.
***************************************************************************/
void DrawableBridge::ReplacePiece(DrawableRoadbed *oldPiece, DrawableRoadbed *newPiece)
{
    ShiAssert(oldPiece);
    ShiAssert(oldPiece->InDisplayList());

    if (newPiece)
    {
        ShiAssert( not newPiece->InDisplayList());
        oldPiece->parentList->InsertObject(newPiece);
    }

    oldPiece->parentList->RemoveObject(oldPiece);
}

/***************************************************************************\
    Return the altitude of (and optionally, the normal to) the surface of
 the bridge at the provided location.
\***************************************************************************/
float DrawableBridge::GetGroundLevel(float x, float y, Tpoint *normal)
{
    DrawableRoadbed *roadbed;
    Tpoint pos;

    pos.x = x;
    pos.y = y;

    // Find the right segment to govern this point
    // (Note:  The cast below is safe because only roadbeds get added to this list)
    roadbedObjects.ResetTraversal();
    roadbed = (DrawableRoadbed*)roadbedObjects.GetNextAndAdvance();

    while (roadbed)
    {
        ShiAssert(roadbed->GetClass() == Roadbed);

        if (roadbed->OnRoadbed(&pos, normal))
        {
            return pos.z;
        }

        roadbed = (DrawableRoadbed*)roadbedObjects.GetNextAndAdvance();
    }

    // We didn't find a containing segment
    // We used to assert here, but in instant action, we let tanks go on water right now...
    // So, we use the position of the container object (presumably ground level)
    if (normal)
    {
        normal->x =  0.0f;
        normal->y =  0.0f;
        normal->z = -1.0f;
    }

    return position.z;
}

/***************************************************************************\
    Make sure the object is placed on the ground then draw it.
\***************************************************************************/
void DrawableBridge::Draw(class RenderOTW *renderer, int LOD)
{
    DrawableObject *obj;

    // See if we need to update our ground position
    if (LOD not_eq previousLOD)
    {

        // Update our position to reflect the terrain beneath us
        position.z = renderer->viewpoint->GetGroundLevel(position.x, position.y);
        previousLOD = LOD;

        // Stick all our children at the same height
        roadbedObjects.ResetTraversal();
        obj = roadbedObjects.GetNextAndAdvance();

        while (obj)
        {
            ShiAssert(obj->GetClass() == Roadbed);
            ((DrawableRoadbed*)obj)->ForceZ(position.z);
            obj = roadbedObjects.GetNextAndAdvance();
        }
    }

    // First draw the raodbed (should all be DrawableRoadbed)
    roadbedObjects.ResetTraversal();
    obj = roadbedObjects.GetNextAndAdvance();

    while (obj)
    {
        obj->Draw(renderer, LOD);
        obj = roadbedObjects.GetNextAndAdvance();
    }

    // Then draw the dynamic objects (should all be DrawableGroundVehicle)
    dynamicObjects.ResetTraversal();
    obj = dynamicObjects.GetNextAndAdvance();

    while (obj)
    {
        obj->Draw(renderer, LOD);
        obj = dynamicObjects.GetNextAndAdvance();
    }

    // Finally draw the superstructure
    roadbedObjects.ResetTraversal();
    obj = roadbedObjects.GetNextAndAdvance();

    while (obj)
    {
        ShiAssert(obj->GetClass() == Roadbed);
        ((DrawableRoadbed*)obj)->DrawSuperstructure(renderer, LOD);
        obj = roadbedObjects.GetNextAndAdvance();
    }
}

/***************************************************************************\
    Draw the children of this object (no ground leveling is done).
\***************************************************************************/
void DrawableBridge::Draw(class Render3D *renderer)
{
    DrawableObject *obj;

    // First draw the raodbed (should all be DrawableRoadbed)
    roadbedObjects.ResetTraversal();
    obj = roadbedObjects.GetNextAndAdvance();

    while (obj)
    {
        obj->Draw(renderer);
        obj = roadbedObjects.GetNextAndAdvance();
    }

    // Then draw the dynamic objects (should all be DrawableGroundVehicle)
    dynamicObjects.ResetTraversal();
    obj = dynamicObjects.GetNextAndAdvance();

    while (obj)
    {
        obj->Draw(renderer);
        obj = dynamicObjects.GetNextAndAdvance();
    }

    // Finally draw the superstructure
    roadbedObjects.ResetTraversal();
    obj = roadbedObjects.GetNextAndAdvance();

    while (obj)
    {
        ShiAssert(obj->GetClass() == Roadbed);
        ((DrawableRoadbed*)obj)->DrawSuperstructure(renderer);
        obj = roadbedObjects.GetNextAndAdvance();
    }
}

/***************************************************************************
    Handle the UpdateMetrics callback from the parent ObjectDisplayList
***************************************************************************/
void DrawableBridge::UpdateMetrics(void *self, long listNo, const Tpoint *pos, TransportStr *transList)
{
    ((DrawableBridge*)self)->UpdateMetrics(listNo, pos, transList);
}
void DrawableBridge::UpdateMetrics(long listNo, const Tpoint *pos, TransportStr *transList)
{
    DrawableObject *obj;
    DrawableObject *objNext;
    float checkDistance;

    // Have the object lists update their sort metrics.
    // (This could be sped up alot by presorting the bridge and reversing the order only when
    //  the viewer crosses into the opposite hemisphere with respect to the bridges yaw.)
    roadbedObjects.UpdateMetrics(pos);
    dynamicObjects.UpdateMetrics(listNo, pos, transList);

    // Check each dynamic object for continued membership in this container
    // (could hold this out of the parent list until after we check for
    //  new members, but this difference should normally be very small)
    dynamicObjects.ResetTraversal();
    obj = dynamicObjects.GetNextAndAdvance();

    while (obj)
    {

        // Push the object back up to our parent list if it has moved beyond our area
        if ( not ObjectInside(obj))
        {
            ShiAssert(obj->GetClass() == GroundVehicle);
            dynamicObjects.RemoveObject(obj);
            parentList->InsertObject(obj);
        }

        obj = dynamicObjects.GetNextAndAdvance();
    }

    // Check behind us in our parent list for new dynamic objects in our area
    checkDistance = distance + 2.0f * Radius();
    obj = prev;

    while (obj and (obj->distance < checkDistance))
    {

        // Pull object down from our parent list if it's inside our area
        objNext = obj->prev;

        if (ObjectInside(obj) and (obj->GetClass() == GroundVehicle))
        {
            parentList->RemoveObject(obj);
            dynamicObjects.InsertObject(obj);
            ((DrawableGroundVehicle*)obj)->SetUpon(this);
        }

        obj = objNext;
    }

    // Check in front of us in our parent list for new dynamic objects in our area
    checkDistance = distance;
    obj = next;

    while (obj and (obj->distance > checkDistance))
    {

        // Pull object down from our parent list if it's inside our area
        objNext = obj->next;

        if (ObjectInside(obj) and (obj->GetClass() == GroundVehicle))
        {
            parentList->RemoveObject(obj);
            dynamicObjects.InsertObject(obj);
            ((DrawableGroundVehicle*)obj)->SetUpon(this);
        }

        obj = objNext;
    }
}

/***************************************************************************\
    Handle the SortForViewpoint callback from the parent ObjectDisplayList
\***************************************************************************/
void DrawableBridge::SortForViewpoint(void *self)
{
    ((DrawableBridge*)self)->SortForViewpoint();
}
void DrawableBridge::SortForViewpoint(void)
{
    // Have the object lists reorder themselves.
    // (This could be sped up alot by presorting the bridge and reversing the order only when
    //  the viewer crosses the into the opposite hemisphere with respect to the bridges yaw.)
    roadbedObjects.SortForViewpoint();
    dynamicObjects.SortForViewpoint();
}

/***************************************************************************\
    See if an object is within our area, and if so, grab it from it's
 parent.
\***************************************************************************/
BOOL DrawableBridge::ObjectInside(DrawableObject *obj)
{
    Tpoint objPos;

    ShiAssert(obj);

    // Get the position of the object under consideration
    obj->GetPosition(&objPos);

    // return our conclusion
    return ((objPos.x >= minX) and (objPos.x <= maxX) and (objPos.y >= minY) and (objPos.y <= maxY));
}

/***************************************************************************\
    Add ourselves to our parent list and request callbacks
\***************************************************************************/
void DrawableBridge::SetParentList(ObjectDisplayList *list)
{
    DrawableObject *obj;

    // Remove ourselves from our old parent's call chain
    if (parentList)
    {
        parentList->RemoveUpdateCallbacks(&updateCBstruct, &sortCBstruct, this);

        // Promote all dynamnic children back up into our old parent's list
        dynamicObjects.ResetTraversal();
        obj = dynamicObjects.GetNextAndAdvance();

        while (obj)
        {
            dynamicObjects.RemoveObject(obj);
            parentList->InsertObject(obj);
            obj = dynamicObjects.GetNextAndAdvance();
        }
    }

    // Record our new parent
    parentList = list;

    // Add ourselves to our new parent's call chain
    if (parentList)
    {
        parentList->InsertUpdateCallbacks(&updateCBstruct, &sortCBstruct, this);
    }
}

redpajama_set_name: RedPajamaGithub


text:
Features:
  - Berkshelf now supports bastion (`berks upload`)

## 1.1.1 (September 27, 2016)

Bugfixes:
  - Fixed the issue with `knife bastion status` plugin, when it sometimes failed to detect bastion host IP address

## 1.1.0 (August 30, 2016)

Changes:
  - Proxy code has been refactored to make it more generic, so it can be used to proxy any requests through bastion connection

Bugfixes:

## 1.0.0 (August 22, 2016)

Features:

  - Connect to bastion server via SSH and proxy all Chef requests through this connection
  - Knife plugins to monitor status, start and stop connections


text:
 var request = require('request');
 var neo4j = require('node-neo4j');
 require('../testserver.js').startserver();
 jasmine.getEnv().defaultTimeoutInterval = 99999;
 describe('Localr API', function() {
     describe('test local connection', function() {
         it('make connection to server', function(done) {
             var url = 'http://localhost:8080/users/test';
             // getting the parameters
             var params = {
                 uri: url,
                 headers: {
                     authorization: getBasic('testuser', 'test')
                 }
             };
             request.get(params, function(error, response, body) {
                 expect(response.statusCode).toBe(200);
                 expect(body).toBe('"works"');
                 if(error) {
                     expect(error.code).not.toBe('ECONNREFUSED');
                 }
                 done();
             })

         })
     })
     describe('Users', function() {
         it("be able to create a user", function(done) {
             var url = 'http://localhost:8080/users';
             var doc = {
                 city: "Birmingham",
                 dob: "31.05.1991",
                 firstname: "Adam",
                 surname: "Holt",
                 email: "adamholt@me.com"
             }
             // getting the parameters
             var params = {
                 uri: url,
                 headers: {
                     authorization: getBasic('testuser', 'test'),
                     "content-type": "application/json"
                 },
                 body: JSON.stringify(doc)
             };
             request.post(params, function(error, response, body) {
                 expect(response.statusCode).toBe(201);
                 body = JSON.parse(body);
                 expect(body.username).toBe('testuser');
                 if(error) {
                     expect(error.code).not.toBe('ECONNREFUSED');
                 }
                 done();
             })
         })
         it("be not able to create duplicate user", function(done) {
             var url = 'http://localhost:8080/users';
             var doc = {
                 city: "Birmingham",
                 dob: "31.05.1991",
                 firstname: "Adam",
                 surname: "Holt",
                 email: "adamholt@me.com"
             }
             // getting the parameters
             var params = {
                 uri: url,
                 headers: {
                     authorization: getBasic('testuser', 'test'),
                     "content-type": "application/json"
                 },
                 body: JSON.stringify(doc)
             };
             request.post(params, function(error, response, body) {
                 expect(response.statusCode).toBe(409);
                 if(error) {
                     expect(error.code).not.toBe('ECONNREFUSED');
                 }
                 done();
             })
         })
     })
     describe('businesses', function() {
         it('able to create new business', function(done) {
             var url = 'http://localhost:8080/business';
             var doc = {
                 points: 50,
                 city: "coventry",
                 address: "blahhh",
                 postcode: "B23 5XR",
                 longitude: 40.000,
                 latitude: 1.020,
                 email: "adamholt@me.com"
             }
             // getting the parameters
             var params = {
                 uri: url,
                 headers: {
                     authorization: getBasic('testbusiness', 'test'),
                     "content-type": "application/json"
                 },
                 body: JSON.stringify(doc)
             };
             request.post(params, function(error, response, body) {
                 expect(response.statusCode).toBe(201);
                 body = JSON.parse(body);
                 expect(body.register).toBe('OK');
                 if(error) {
                     expect(error.code).not.toBe('ECONNREFUSED');
                 }
                 done();
             })
         })
         it('should not be able to duplicate business', function(done) {
             var url = 'http://localhost:8080/business';
             var doc = {
                 points: 50,
                 city: "coventry",
                 address: "blahhh",
                 postcode: "B23 5XR",
                 longitude: 40.000,
                 latitude: 1.020,
                 email: "adamholt@me.com"
             }
             // getting the parameters
             var params = {
                 uri: url,
                 headers: {
                     authorization: getBasic('testbusiness', 'test'),
                     "content-type": "application/json"
                 },
                 body: JSON.stringify(doc)
             };
             request.post(params, function(error, response, body) {
                 expect(response.statusCode).toBe(409);
                 if(error) {
                     expect(error.code).not.toBe('ECONNREFUSED');
                 }
                 done();
             })
         })
     })
     describe('checkin', function() {
         it("be able to checkin", function(done) {
             var url = 'http://localhost:8080/users/checkin';
             var doc = {
                 business: "testbusiness",
             };
             // getting the parameters
             var params = {
                 uri: url,
                 headers: {
                     authorization: getBasic('testuser', 'test'),
                     "content-type": "application/json"
                 },
                 body: JSON.stringify(doc)
             };
             request.put(params, function(error, response, body) {
                 expect(response.statusCode).toBe(202);
                 body = JSON.parse(body);
                 expect(body.CheckIn).toBe("Ok")
                 if(error) {
                     expect(error.code).not.toBe('ECONNREFUSED');
                 }
                 done();
             })
         })
         it("should not be able to checkin with invalid credntials", function(done) {
             var url = 'http://localhost:8080/users/checkin';
             var doc = {
                 business: "testbusiness",
             };
             // getting the parameters
             var params = {
                 uri: url,
                 headers: {
                     authorization: getBasic('testuser', 'wrongpass'),
                     "content-type": "application/json"
                 },
                 body: JSON.stringify(doc)
             };
             request.put(params, function(error, response, body) {
                 expect(response.statusCode).toBe(401);
                 body = JSON.parse(body);
                 expect(body.message).toBe("Invalid username/password")
                 if(error) {
                     expect(error.code).not.toBe('ECONNREFUSED');
                 }
                 done();
             })
         })
         it("check points have been added", function(done) {
             var url = 'http://localhost:8080/users/get/testuser';
             // getting the parameters
             var params = {
                 uri: url,
                 headers: {
                     authorization: getBasic('testuser', 'test')
                 }
             };
             request.get(params, function(error, response, body) {
                 expect(response.statusCode).toBe(200);
                 body = JSON.parse(body);
                 expect(body.points).toBe(50);
                 if(error) {
                     expect(error.code).not.toBe('ECONNREFUSED');
                 }
                 done();
             })
         })
         it("be able to see where you've checked in", function(done) {
             var url = 'http://localhost:8080/users/get/testuser';
             // getting the parameters
             var params = {
                 uri: url,
                 headers: {
                     authorization: getBasic('testuser', 'test')
                 }
             };
             request.get(params, function(error, response, body) {
                 expect(response.statusCode).toBe(200);
                 body = JSON.parse(body);
                 var trans = body.transactions;
                 expect(trans.length).toBeGreaterThan(0);
                 if(error) {
                     expect(error.code).not.toBe('ECONNREFUSED');
                 }
                 done();
             })
         })
     })
     describe("groups", function() {
         it("be able to create a group", function(done) {
             var db = new neo4j('http://localhost:7474');
             var url = 'http://localhost:8080/groups'
             var doc = {
                 username: "testuser",
                 groupname: "testgroup",
                 description: "This is a Test Group",
                 competition: "freshers"
             };
             // getting the parameters
             var params = {
                 uri: url,
                 headers: {
                     authorization: getBasic('testuser', 'test'),
                     "content-type": "application/json"
                 },
                 body: JSON.stringify(doc)
             };
             // create the competition node
             db.insertNode({
                 name: "freshers"
             }, ['competition'], function(err, node) {
                 if(err) throw err;

                 request.post(params, function(error, response, body) {
                     expect(response.statusCode).toBe(201);
                     if(error) {
                         expect(error.code).not.toBe('ECONNREFUSED');
                     }
                     db.cypherQuery(" MATCH (n:Group) WHERE n.name ='testgroup' RETURN n", function(err, Results) {
                         if(err) throw err;
                         expect(Results.data[0].name).toBe('testgroup');
                         db.cypherQuery(" MATCH n-[r]->m RETURN n,r,m", function(err, Results) {
                             if(err) throw err;

                             done();
                         })
                     })
                 })
             });
         })
         it("be able to join a group", function(done) {
             var url = 'http://localhost:8080/users';
             var doc = {
                 city: "Birmingham",
                 dob: "11.01.1992",
                 firstname: "Reiss",
                 surname: "Jarvis",
                 email: "adamholt@me.com"
             }
             // getting the parameters
             // create new user first
             var params = {
                 uri: url,
                 headers: {
                     authorization: getBasic('testuser2', 'test'),
                     "content-type": "application/json"
                 },
                 body: JSON.stringify(doc)
             };
             request.post(params, function(error, response, body) {
                 //create group

                 var url = 'http://localhost:8080/groups'
                 var doc = {
                     username: "testuser2",
                     groupname: "testgroup2",
                     description: "This is a Test Group 2",
                     competition: "freshers"
                 };

                 var params = {
                     uri: url,
                     headers: {
                         authorization: getBasic('testuser2', 'test'),
                         "content-type": "application/json"
                     },
                     body: JSON.stringify(doc)
                 };

                 request.post(params, function(error, response, body) {
                     //join the group

                     url = 'http://localhost:8080/groups/join/testgroup2'
                     var params = {
                         uri: url,
                         headers: {
                             authorization: getBasic('testuser', 'test'),
                             "content-type": "application/json"
                         }
                     };
                     request.post(params, function(error, response, body) {
                         expect(response.statusCode).toBe(201);

                         if(error) {
                             expect(error.code).not.toBe('ECONNREFUSED');
                         }
                         done()
                     })
                 })
             });
         })
         it("Be able to get a single group", function(done) {
             var url = 'http://localhost:8080/groups/testgroup';
             // getting the parameters
             var params = {
                 uri: url,
                 headers: {
                     authorization: getBasic('testbusiness', 'test'),
                     "content-type": "application/json"
                 },
             };
             request.get(params, function(error, response, body) {
                 expect(response.statusCode).toBe(200);

                 if(error) {
                     expect(error.code).not.toBe('ECONNREFUSED');
                 }
                 done();
             })
         })
         it("Be able to see all groups", function(done) {
             var url = 'http://localhost:8080/groups?competition=freshers';
             // getting the parameters
             var params = {
                 uri: url,
                 headers: {
                     authorization: getBasic('testuser', 'test'),
                     "content-type": "application/json"
                 },
             };
             request.get(params, function(error, response, body) {
                 expect(response.statusCode).toBe(200);
                 body = JSON.parse(body);
                 expect(body.total_groups).toBe(2);
                 if(error) {
                     expect(error.code).not.toBe('ECONNREFUSED');
                 }
                 done();
             })
         })
     })
     describe('Offers', function() {
         it("Be able to add an offer", function(done) {
             var url = 'http://localhost:8080/business/offers';
             var doc = {
                 businessname: 'testbusiness',
                 description: 'description',
                 title: 'test offer',
                 cost: 25
             }
             // getting the parameters
             var params = {
                 uri: url,
                 headers: {
                     authorization: getBasic('testbusiness', 'test'),
                     "content-type": "application/json"
                 },
                 body: JSON.stringify(doc)
             };
             request.post(params, function(error, response, body) {
                 expect(response.statusCode).toBe(201);
                 if(error) {
                     expect(error.code).not.toBe('ECONNREFUSED');
                 }
                 done();
             })
         })
         it("Be able to get the latest offers", function(done) {
             var url = 'http://localhost:8080/business/offers/all';
             // getting the parameters
             var params = {
                 uri: url,
                 headers: {
                     authorization: getBasic('testuser', 'test'),
                     "content-type": "application/json"
                 },
             };
             request.get(params, function(error, response, body) {
                 expect(response.statusCode).toBe(200);
                 if(error) {
                     expect(error.code).not.toBe('ECONNREFUSED');
                 }
                 done();
             })
         })
         it("be able to get a businesses offers", function(done) {
             var url = 'http://localhost:8080/business/offers/testbusiness';
             // getting the parameters
             var params = {
                 uri: url,
                 headers: {
                     authorization: getBasic('testuser', 'test'),
                     "content-type": "application/json"
                 },
             };
             request.get(params, function(error, response, body) {
                 expect(response.statusCode).toBe(200);
                 if(error) {
                     expect(error.code).not.toBe('ECONNREFUSED');
                 }
                 done();
             })
         })
         it("be able to redeem an offer", function(done) {
             var url = 'http://localhost:8080/business/offers/redeem';
             var doc = {
                 offerTitle: 'test offer - testbusiness'
             }
             // getting the parameters
             var params = {
                 uri: url,
                 headers: {
                     authorization: getBasic('testuser', 'test'),
                     "content-type": "application/json"
                 },
                 body: JSON.stringify(doc)
             };
             request.put(params, function(error, response, body) {
                 expect(response.statusCode).toBe(202);
                 body = JSON.parse(body)

                 expect(body.Redeem).toBe("OK")
                 expect(body.username).toBe("testuser")
                 if(error) {
                     expect(error.code).not.toBe('ECONNREFUSED');
                 }
                 done();
             })
         })
         it("should not be able to redeem an offer with wrong credentials", function(done) {
             var url = 'http://localhost:8080/business/offers/redeem';
             var doc = {
                 offerTitle: 'test offer - testbusiness'
             }
             // getting the parameters
             var params = {
                 uri: url,
                 headers: {
                     authorization: getBasic('testuser', 'wrong'),
                     "content-type": "application/json"
                 },
                 body: JSON.stringify(doc)
             };
             request.put(params, function(error, response, body) {
                 expect(response.statusCode).toBe(401);
                 body = JSON.parse(body);
                 expect(body.message).toBe("Invalid username/password")
                 if(error) {
                     expect(error.code).not.toBe('ECONNREFUSED');
                 }
                 done();
             })
         })
         it("be able to check what offers youve redeemed", function(done) {
             var url = 'http://localhost:8080/users/get/testuser';
             var params = {
                 uri: url,
                 headers: {
                     authorization: getBasic('testuser', 'test')
                 },
             };
             request.get(params, function(error, response, body) {
                 expect(response.statusCode).toBe(200);
                 body = JSON.parse(body);
                 expect(body.transactions[0].checked_in_at).toBe("testbusiness")
                 expect(body.transactions[1].business_redeemed).toBe("testbusiness")
                 if(error) {
                     expect(error.code).not.toBe('ECONNREFUSED');
                 }
                 done();
             })
         })
     })
     describe('delete all', function() {
         it("be able to delete the user", function(done) {
             var url = 'http://localhost:8080/users/testuser';
             // getting the parameters
             var params = {
                 uri: url,
                 headers: {
                     authorization: getBasic('testuser', 'test')
                 },
             };
             request.del(params, function(error, response, body) {
                 expect(response.statusCode).toBe(200);
                 expect(body).toBe('"Deleted User!"')
                 if(error) {
                     expect(error.code).not.toBe('ECONNREFUSED');
                 }
                 done();
             })
         })
         it('be able to delete the business', function(done) {
             var url = 'http://localhost:8080/business/testbusiness';
             // getting the parameters
             var params = {
                 uri: url,
                 headers: {
                     authorization: getBasic('testbusiness', 'test')
                 },
             };
             request.del(params, function(error, response, body) {
                 expect(response.statusCode).toBe(200);
                 expect(body).toBe('"Deleted Business!"')
                 if(error) {
                     expect(error.code).not.toBe('ECONNREFUSED');
                 }
                 done();
             })
         })
         it('delete group', function(done) {
             var url = 'http://localhost:8080/groups/testgroup';
             // getting the parameters
             request.del(url, function(error, response, body) {
                 expect(response.statusCode).toBe(200);
                 expect(response.body).toBe('"group deleted"')
                 if(error) {
                     expect(error.code).not.toBe('ECONNREFUSED');
                 }
                 done();
             })
         })
     });
 })
 getBasic = function(username, password) {
     return "Basic " + new Buffer(username + ":" + password).toString('base64')
 };


text:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>com.googlecode.concurrenttrees.radix.node.concrete Class Hierarchy (Concurrent-Trees 2.6.0 API)</title>
<meta name="date" content="2016-07-12">
<link rel="stylesheet" type="text/css" href="../../../../../../stylesheet.css" title="Style">

JavaScript is disabled on your browser.

Skip navigation links

Overview

Package

Class

Use

Tree

Deprecated

Index

Help

Prev

Next

Frames

No Frames

All Classes

Hierarchy For Package com.googlecode.concurrenttrees.radix.node.concrete

Package Hierarchies:

All Packages

Class Hierarchy

java.lang.Object

com.googlecode.concurrenttrees.radix.node.concrete.DefaultByteArrayNodeFactory (implements com.googlecode.concurrenttrees.radix.node.NodeFactory)

com.googlecode.concurrenttrees.radix.node.concrete.DefaultCharArrayNodeFactory (implements com.googlecode.concurrenttrees.radix.node.NodeFactory)

com.googlecode.concurrenttrees.radix.node.concrete.DefaultCharSequenceNodeFactory (implements com.googlecode.concurrenttrees.radix.node.NodeFactory)

com.googlecode.concurrenttrees.radix.node.concrete.SmartArrayBasedNodeFactory (implements com.googlecode.concurrenttrees.radix.node.NodeFactory)

Skip navigation links

Overview

Package

Class

Use

Tree

Deprecated

Index

Help

Prev

Next

Frames

No Frames

All Classes

Copyright © 2016. All Rights Reserved.