func (suite *OcppJTestSuite) TestCentralSystemSendConfirmation() {
	t := suite.T()
	mockChargePointId := "0101"
	mockUniqueId := "1234"
	suite.mockServer.On("Start", mock.AnythingOfType("int"), mock.AnythingOfType("string")).Return(nil)
	suite.mockServer.On("Write", mock.AnythingOfType("string"), mock.Anything).Return(nil)
	suite.centralSystem.Start(8887, "/{ws}")
	suite.serverDispatcher.CreateClient(mockChargePointId)
	mockConfirmation := newMockConfirmation("mockValue")
	err := suite.centralSystem.SendResponse(mockChargePointId, mockUniqueId, mockConfirmation)
	assert.Nil(t, err)
}
----------------- SendResponse tests -----------------
package ocppj_test
import (
	"encoding/json"
	"fmt"
	"strconv"
	"sync"
	"time"
	"github.com/stretchr/testify/assert"
	"github.com/stretchr/testify/mock"
	"github.com/stretchr/testify/require"
	"github.com/lorenzodonini/ocpp-go/ocpp"
	"github.com/lorenzodonini/ocpp-go/ocppj"
	"github.com/lorenzodonini/ocpp-go/ws"
)
func (suite *OcppJTestSuite) TestNewServer() {
	s := ocppj.NewServer(nil, nil, nil)
	assert.NotNil(suite.T(), s)
}
func (suite *OcppJTestSuite) TestServerStart() {
	suite.mockServer.On("Start", mock.AnythingOfType("int"), mock.AnythingOfType("string")).Return(nil)
	suite.centralSystem.Start(8887, "/{ws}")
	assert.True(suite.T(), suite.serverDispatcher.IsRunning())
}
func (suite *OcppJTestSuite) TestServerNotStartedError() {
	t := suite.T()
	mockChargePointId := "1234"
	req := newMockRequest("somevalue")
	err := suite.centralSystem.SendRequest(mockChargePointId, req)
	require.Error(t, err, "ocppj server is not started, couldn't send request")
	assert.False(t, suite.serverDispatcher.IsRunning())
}
func (suite *OcppJTestSuite) TestServerStoppedError() {
	t := suite.T()
	mockChargePointId := "1234"
	suite.mockServer.On("Start", mock.AnythingOfType("int"), mock.AnythingOfType("string")).Return(nil)
	suite.mockServer.On("Stop").Return(nil)
	suite.centralSystem.Start(8887, "/{ws}")
	suite.centralSystem.Stop()
	time.Sleep(20 * time.Millisecond)
	assert.False(t, suite.serverDispatcher.IsRunning())
	req := newMockRequest("somevalue")
	err := suite.centralSystem.SendRequest(mockChargePointId, req)
	assert.Error(t, err, "ocppj server is not started, couldn't send request")
}
func (suite *OcppJTestSuite) TestCentralSystemSendRequest() {
	mockChargePointId := "1234"
	suite.mockServer.On("Start", mock.AnythingOfType("int"), mock.AnythingOfType("string")).Return(nil)
	suite.mockServer.On("Write", mockChargePointId, mock.Anything).Return(nil)
	suite.centralSystem.Start(8887, "/{ws}")
	suite.serverDispatcher.CreateClient(mockChargePointId)
	mockRequest := newMockRequest("mockValue")
	err := suite.centralSystem.SendRequest(mockChargePointId, mockRequest)
	assert.Nil(suite.T(), err)
}
func (suite *OcppJTestSuite) TestCentralSystemSendInvalidRequest() {
	mockChargePointId := "1234"
	suite.mockServer.On("Start", mock.AnythingOfType("int"), mock.AnythingOfType("string")).Return(nil)
	suite.mockServer.On("Write", mockChargePointId, mock.Anything).Return(nil)
	suite.centralSystem.Start(8887, "/{ws}")
	suite.serverDispatcher.CreateClient(mockChargePointId)
	mockRequest := newMockRequest("")
	err := suite.centralSystem.SendRequest(mockChargePointId, mockRequest)
	assert.NotNil(suite.T(), err)
}
func (suite *OcppJTestSuite) TestServerSendInvalidJsonRequest() {
	mockChargePointId := "1234"
	suite.mockServer.On("Start", mock.AnythingOfType("int"), mock.AnythingOfType("string")).Return(nil)
	suite.mockServer.On("Write", mockChargePointId, mock.Anything).Return(nil)
	suite.centralSystem.Start(8887, "/{ws}")
	suite.serverDispatcher.CreateClient(mockChargePointId)
	mockRequest := newMockRequest("somevalue")
	mockRequest.MockAny = make(chan int)
	err := suite.centralSystem.SendRequest(mockChargePointId, mockRequest)
	require.Error(suite.T(), err)
	assert.IsType(suite.T(), &json.UnsupportedTypeError{}, err)
}
func (suite *OcppJTestSuite) TestServerSendInvalidCall() {
	mockChargePointId := "1234"
	suite.mockServer.On("Start", mock.AnythingOfType("int"), mock.AnythingOfType("string")).Return(nil)
	suite.mockServer.On("Write", mockChargePointId, mock.Anything).Return(nil)
	suite.centralSystem.Start(8887, "/{ws}")
	suite.serverDispatcher.CreateClient(mockChargePointId)
	mockRequest := newMockRequest("somevalue")
	suite.centralSystem.Profiles = []*ocpp.Profile{}
	err := suite.centralSystem.SendRequest(mockChargePointId, mockRequest)
	assert.Error(suite.T(), err, fmt.Sprintf("Couldn't create Call for unsupported action %v", mockRequest.GetFeatureName()))
}
func (suite *OcppJTestSuite) TestCentralSystemSendRequestFailed() {
	t := suite.T()
	mockChargePointId := "1234"
	var callID string
	suite.mockServer.On("Start", mock.AnythingOfType("int"), mock.AnythingOfType("string")).Return(nil)
	suite.mockServer.On("Write", mock.AnythingOfType("string"), mock.Anything).Return(fmt.Errorf("networkError")).Run(func(args mock.Arguments) {
		clientID := args.String(0)
		q, ok := suite.serverRequestMap.Get(clientID)
		require.True(t, ok)
		require.False(t, q.IsEmpty())
		req := q.Peek().(ocppj.RequestBundle)
		callID = req.Call.GetUniqueId()
		_, ok = suite.centralSystem.RequestState.GetClientState(mockChargePointId).GetPendingRequest(callID)
		assert.True(t, ok)
	})
	suite.centralSystem.Start(8887, "/{ws}")
	suite.serverDispatcher.CreateClient(mockChargePointId)
	mockRequest := newMockRequest("mockValue")
	err := suite.centralSystem.SendRequest(mockChargePointId, mockRequest)
	assert.Nil(t, err)
	time.Sleep(500 * time.Millisecond)
	_, ok := suite.centralSystem.RequestState.GetClientState(mockChargePointId).GetPendingRequest(callID)
	assert.False(t, ok)
}