VOL-1838, VOL-1909, VOL-1906 and VOL-1911
Updated Device_handler.go test cases.
Adding Unit testcases for olt_platform.go, olt_event_mgr.go and statsmanager.go

Change-Id: I5b64df9a08fa20dd63bfd729c5f086526a9a1d74
diff --git a/mocks/mockAdapterProxy.go b/mocks/mockAdapterProxy.go
index a91d361..1b8ada7 100644
--- a/mocks/mockAdapterProxy.go
+++ b/mocks/mockAdapterProxy.go
@@ -38,10 +38,8 @@
 	toDeviceID string,
 	proxyDeviceID string,
 	messageID string) error {
-	//panic("implement me")
-	if ctx == nil || msg == nil || fromAdapter != "" ||
-		toAdapter != "" || toDeviceID != "" || proxyDeviceID != "" || messageID != "" {
-		return errors.New("sendInterAdapterMessage func parameters cannot be nil")
+	if toDeviceID == "" {
+		return errors.New("no deviceid")
 	}
 	return nil
 }
diff --git a/mocks/mockCoreProxy.go b/mocks/mockCoreProxy.go
index 6abf628..77b4c08 100644
--- a/mocks/mockCoreProxy.go
+++ b/mocks/mockCoreProxy.go
@@ -20,6 +20,7 @@
 import (
 	"context"
 	"errors"
+	"fmt"
 
 	"github.com/opencord/voltha-go/kafka"
 	"github.com/opencord/voltha-protos/go/voltha"
@@ -29,106 +30,166 @@
 type MockCoreProxy struct {
 	// Values to be used in test can reside inside this structure
 	// TODO store relevant info in this, use this info for negative and positive tests
+	Devices map[string]*voltha.Device
 }
 
 // UpdateCoreReference mock updatesCoreReference
-func (mp *MockCoreProxy) UpdateCoreReference(deviceID string, coreReference string) {
+func (mcp *MockCoreProxy) UpdateCoreReference(deviceID string, coreReference string) {
 	panic("implement me")
 }
 
 // DeleteCoreReference mock DeleteCoreReference function
-func (mp *MockCoreProxy) DeleteCoreReference(deviceID string) {
+func (mcp *MockCoreProxy) DeleteCoreReference(deviceID string) {
 	panic("implement me")
 }
 
 // GetCoreTopic implements mock GetCoreTopic
-func (mp *MockCoreProxy) GetCoreTopic(deviceID string) kafka.Topic {
+func (mcp *MockCoreProxy) GetCoreTopic(deviceID string) kafka.Topic {
 	panic("implement me")
 }
 
 // GetAdapterTopic implements mock GetAdapterTopic
-func (mp *MockCoreProxy) GetAdapterTopic(args ...string) kafka.Topic {
+func (mcp *MockCoreProxy) GetAdapterTopic(args ...string) kafka.Topic {
 	panic("implement me")
 }
 
 // RegisterAdapter implements mock RegisterAdapter
-func (mp *MockCoreProxy) RegisterAdapter(ctx context.Context, adapter *voltha.Adapter,
+func (mcp *MockCoreProxy) RegisterAdapter(ctx context.Context, adapter *voltha.Adapter,
 	deviceTypes *voltha.DeviceTypes) error {
 	if ctx == nil || adapter == nil || deviceTypes == nil {
-
 		return errors.New("registerAdapter func parameters cannot be nil")
 	}
 	return nil
-
 }
 
 // DeviceUpdate implements mock DeviceUpdate
-func (mp *MockCoreProxy) DeviceUpdate(ctx context.Context, device *voltha.Device) error {
-	panic("implement me")
+func (mcp *MockCoreProxy) DeviceUpdate(ctx context.Context, device *voltha.Device) error {
+	if device.Id == "" {
+		return errors.New("no Device")
+	}
+	return nil
 }
 
 // PortCreated implements mock PortCreated
-func (mp *MockCoreProxy) PortCreated(ctx context.Context, deviceID string, port *voltha.Port) error {
-	panic("implement me")
+func (mcp *MockCoreProxy) PortCreated(ctx context.Context, deviceID string, port *voltha.Port) error {
+	if deviceID == "" {
+		return errors.New("no deviceID")
+	}
+	if port.Type > 7 {
+		return errors.New("invalid porttype")
+	}
+	return nil
 }
 
 // PortsStateUpdate implements mock PortsStateUpdate
-func (mp *MockCoreProxy) PortsStateUpdate(ctx context.Context, deviceID string, operStatus voltha.OperStatus_OperStatus) error {
-	panic("implement me")
+func (mcp *MockCoreProxy) PortsStateUpdate(ctx context.Context, deviceID string, operStatus voltha.OperStatus_OperStatus) error {
+	if deviceID == "" {
+		return errors.New("no Device")
+	}
+	return nil
 }
 
 // DeleteAllPorts implements mock DeleteAllPorts
-func (mp *MockCoreProxy) DeleteAllPorts(ctx context.Context, deviceID string) error {
-	panic("implement me")
+func (mcp *MockCoreProxy) DeleteAllPorts(ctx context.Context, deviceID string) error {
+	if deviceID == "" {
+		return errors.New("no Device id")
+	}
+	return nil
 }
 
 // DeviceStateUpdate implements mock DeviceStateUpdate
-func (mp *MockCoreProxy) DeviceStateUpdate(ctx context.Context, deviceID string,
+func (mcp *MockCoreProxy) DeviceStateUpdate(ctx context.Context, deviceID string,
 	connStatus voltha.ConnectStatus_ConnectStatus, operStatus voltha.OperStatus_OperStatus) error {
-	panic("implement me")
+	if deviceID == "" {
+		return errors.New("no Device id")
+	}
+	return nil
 }
 
 // ChildDeviceDetected implements mock ChildDeviceDetected
-func (mp *MockCoreProxy) ChildDeviceDetected(ctx context.Context, parentDeviceID string, parentPortNo int,
+func (mcp *MockCoreProxy) ChildDeviceDetected(ctx context.Context, parentdeviceID string, parentPortNo int,
 	childDeviceType string, channelID int, vendorID string, serialNumber string, onuID int64) (*voltha.Device, error) {
-	panic("implement me")
+	if parentdeviceID == "" {
+		return nil, errors.New("no deviceID")
+	}
+	return nil, nil
 }
 
-// ChildDevicesLost implements mock ChildDevicesLost
-func (mp *MockCoreProxy) ChildDevicesLost(ctx context.Context, parentDeviceID string) error {
-	panic("implement me")
+// ChildDevicesLost implements mock ChildDevicesLost.
+func (mcp *MockCoreProxy) ChildDevicesLost(ctx context.Context, parentdeviceID string) error {
+	//panic("implement me")
+	if parentdeviceID == "" {
+		return errors.New("no device id")
+	}
+	return nil
 }
 
 // ChildDevicesDetected implements mock ChildDevicesDetecte
-func (mp *MockCoreProxy) ChildDevicesDetected(ctx context.Context, parentDeviceID string) error {
-	panic("implement me")
+func (mcp *MockCoreProxy) ChildDevicesDetected(ctx context.Context, parentdeviceID string) error {
+	if parentdeviceID == "" {
+		return errors.New("no device id")
+	}
+	return nil
 }
 
 // GetDevice implements mock GetDevice
-func (mp *MockCoreProxy) GetDevice(ctx context.Context, parentDeviceID string, deviceID string) (*voltha.Device, error) {
-	if parentDeviceID != "" {
-		return &voltha.Device{}, nil
+func (mcp *MockCoreProxy) GetDevice(ctx context.Context, parentdeviceID string, deviceID string) (*voltha.Device, error) {
+	if parentdeviceID == "" || deviceID == "" {
+		return &voltha.Device{}, errors.New("no deviceID")
+	}
+	for k, v := range mcp.Devices {
+		if k == "olt" {
+			return v, nil
+		}
 	}
 	return nil, errors.New("device detection failed")
 }
 
 // GetChildDevice implements mock GetChildDevice
-func (mp *MockCoreProxy) GetChildDevice(ctx context.Context, parentDeviceID string, kwargs map[string]interface{}) (*voltha.Device, error) {
-	if parentDeviceID != "" {
-		return &voltha.Device{}, nil
+func (mcp *MockCoreProxy) GetChildDevice(ctx context.Context, parentdeviceID string, kwargs map[string]interface{}) (*voltha.Device, error) {
+
+	if parentdeviceID == "" {
+		return nil, errors.New("device detection failed")
 	}
+	onuID := kwargs["onu_id"]
+	var onuDevice *voltha.Device
+	for _, val := range mcp.Devices {
+		if val.GetId() == fmt.Sprintf("%v", onuID) {
+			onuDevice = val
+			break
+		}
+	}
+	if onuDevice != nil {
+		return onuDevice, nil
+	}
+	//return &voltha.Device{}, nil
 	return nil, errors.New("device detection failed")
 }
 
 // GetChildDevices implements mock GetChildDevices
-func (mp *MockCoreProxy) GetChildDevices(ctx context.Context, parentDeviceID string) (*voltha.Devices, error) {
-	if parentDeviceID != "" {
-		return &voltha.Devices{}, nil
+func (mcp *MockCoreProxy) GetChildDevices(ctx context.Context, parentdeviceID string) (*voltha.Devices, error) {
+	if parentdeviceID == "" {
+		return nil, errors.New("no deviceID")
+	}
+	onuDevices := make([]*voltha.Device, 0)
+
+	for _, val := range mcp.Devices {
+		if val != nil {
+			onuDevices = append(onuDevices, val)
+		}
+	}
+
+	deviceList := &voltha.Devices{Items: onuDevices}
+	if len(deviceList.Items) > 0 {
+		return deviceList, nil
 	}
 	return nil, errors.New("device detection failed")
 }
 
 // SendPacketIn  implements mock SendPacketIn
-func (mp *MockCoreProxy) SendPacketIn(ctx context.Context, deviceID string, port uint32, pktPayload []byte) error {
-	panic("implement me")
+func (mcp *MockCoreProxy) SendPacketIn(ctx context.Context, deviceID string, port uint32, pktPayload []byte) error {
+	if deviceID == "" {
+		return errors.New("no Device ID")
+	}
+	return nil
 }
diff --git a/mocks/mockEventproxy.go b/mocks/mockEventproxy.go
new file mode 100644
index 0000000..be3049a
--- /dev/null
+++ b/mocks/mockEventproxy.go
@@ -0,0 +1,37 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+
+ * http://www.apache.org/licenses/LICENSE-2.0
+
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+//Package mocks provides the mocks for openolt-adapter.
+package mocks
+
+import (
+	"errors"
+
+	"github.com/opencord/voltha-protos/go/voltha"
+)
+
+// MockEventProxy for mocking EventProxyIntf
+type MockEventProxy struct {
+}
+
+// SendDeviceEvent mocks the SendDeviceEvent function
+func (me *MockEventProxy) SendDeviceEvent(deviceEvent *voltha.DeviceEvent, category voltha.EventCategory_EventCategory,
+	subCategory voltha.EventSubCategory_EventSubCategory, raisedTs int64) error {
+	if raisedTs == 0 {
+		return errors.New("raisedTS cannot be zero")
+	}
+	return nil
+}
diff --git a/mocks/mockOpenOltClient.go b/mocks/mockOpenOltClient.go
new file mode 100644
index 0000000..b3d9077
--- /dev/null
+++ b/mocks/mockOpenOltClient.go
@@ -0,0 +1,224 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+
+ * http://www.apache.org/licenses/LICENSE-2.0
+
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+//Package mocks provides the mocks for openolt-adapter.
+package mocks
+
+import (
+	"context"
+	"errors"
+	"io"
+
+	openolt "github.com/opencord/voltha-protos/go/openolt"
+	tech_profile "github.com/opencord/voltha-protos/go/tech_profile"
+	"google.golang.org/grpc"
+	"google.golang.org/grpc/metadata"
+)
+
+// MockOpenoltClient mock struct for OpenoltClient.
+type MockOpenoltClient struct {
+	counter int
+}
+
+// DisableOlt mocks the DisableOlt function of Openoltclient.
+func (ooc *MockOpenoltClient) DisableOlt(ctx context.Context, in *openolt.Empty, opts ...grpc.CallOption) (*openolt.Empty, error) {
+	//return &openolt.Empty{}, nil
+	if ooc.counter == 0 {
+		ooc.counter++
+		return &openolt.Empty{}, nil
+	}
+	return nil, errors.New("disableOlt failed")
+}
+
+// ReenableOlt mocks the ReenableOlt function of Openoltclient.
+func (ooc *MockOpenoltClient) ReenableOlt(ctx context.Context, in *openolt.Empty, opts ...grpc.CallOption) (*openolt.Empty, error) {
+	if ooc.counter == 0 {
+		ooc.counter++
+		return &openolt.Empty{}, nil
+	}
+	return nil, errors.New("reenable olt failed")
+}
+
+// ActivateOnu mocks the ActivateOnu function of Openoltclient.
+func (ooc *MockOpenoltClient) ActivateOnu(ctx context.Context, in *openolt.Onu, opts ...grpc.CallOption) (*openolt.Empty, error) {
+	if in == nil {
+		return nil, errors.New("invalid onuId")
+	}
+	return &openolt.Empty{}, nil
+}
+
+// DeactivateOnu mocks the DeactivateOnu function of Openoltclient.
+func (ooc *MockOpenoltClient) DeactivateOnu(ctx context.Context, in *openolt.Onu, opts ...grpc.CallOption) (*openolt.Empty, error) {
+	return &openolt.Empty{}, nil
+}
+
+// DeleteOnu mocks the DeleteOnu function of Openoltclient.
+func (ooc *MockOpenoltClient) DeleteOnu(ctx context.Context, in *openolt.Onu, opts ...grpc.CallOption) (*openolt.Empty, error) {
+	return &openolt.Empty{}, nil
+}
+
+// OmciMsgOut mocks the OmciMsgOut function of Openoltclient.
+func (ooc *MockOpenoltClient) OmciMsgOut(ctx context.Context, in *openolt.OmciMsg, opts ...grpc.CallOption) (*openolt.Empty, error) {
+	if in == nil {
+		return nil, errors.New("invalid Omci Msg")
+	}
+	return &openolt.Empty{}, nil
+}
+
+// OnuPacketOut mocks the OnuPacketOut function of Openoltclient.
+func (ooc *MockOpenoltClient) OnuPacketOut(ctx context.Context, in *openolt.OnuPacket, opts ...grpc.CallOption) (*openolt.Empty, error) {
+	return &openolt.Empty{}, nil
+}
+
+// UplinkPacketOut mocks the UplinkPacketOut function of Openoltclient.
+func (ooc *MockOpenoltClient) UplinkPacketOut(ctx context.Context, in *openolt.UplinkPacket, opts ...grpc.CallOption) (*openolt.Empty, error) {
+	return &openolt.Empty{}, nil
+}
+
+// FlowAdd mocks the FlowAdd function of Openoltclient.
+func (ooc *MockOpenoltClient) FlowAdd(ctx context.Context, in *openolt.Flow, opts ...grpc.CallOption) (*openolt.Empty, error) {
+	return &openolt.Empty{}, nil
+}
+
+// FlowRemove mocks the FlowRemove function of Openoltclient.
+func (ooc *MockOpenoltClient) FlowRemove(ctx context.Context, in *openolt.Flow, opts ...grpc.CallOption) (*openolt.Empty, error) {
+	return &openolt.Empty{}, nil
+}
+
+// HeartbeatCheck mocks the HeartbeatCheck function of Openoltclient.
+func (ooc *MockOpenoltClient) HeartbeatCheck(ctx context.Context, in *openolt.Empty, opts ...grpc.CallOption) (*openolt.Heartbeat, error) {
+	return nil, nil
+}
+
+// EnablePonIf mocks the EnablePonIf function of Openoltclient.
+func (ooc *MockOpenoltClient) EnablePonIf(ctx context.Context, in *openolt.Interface, opts ...grpc.CallOption) (*openolt.Empty, error) {
+	return &openolt.Empty{}, nil
+}
+
+// DisablePonIf mocks the DisablePonIf function of Openoltclient.
+func (ooc *MockOpenoltClient) DisablePonIf(ctx context.Context, in *openolt.Interface, opts ...grpc.CallOption) (*openolt.Empty, error) {
+	return &openolt.Empty{}, nil
+}
+
+// GetDeviceInfo mocks the GetDeviceInfo function of Openoltclient.
+func (ooc *MockOpenoltClient) GetDeviceInfo(ctx context.Context, in *openolt.Empty, opts ...grpc.CallOption) (*openolt.DeviceInfo, error) {
+	if ooc.counter == 0 {
+		ooc.counter++
+		deviceInfo := &openolt.DeviceInfo{Vendor: "Openolt", Model: "1.0", HardwareVersion: "1.0", FirmwareVersion: "1.0", DeviceId: "olt", DeviceSerialNumber: "olt"}
+		return deviceInfo, nil
+	}
+	if ooc.counter == 1 {
+		ooc.counter++
+		deviceInfo := &openolt.DeviceInfo{Vendor: "Openolt", Model: "1.0", HardwareVersion: "1.0", FirmwareVersion: "1.0", DeviceId: "", DeviceSerialNumber: "olt"}
+		return deviceInfo, nil
+	}
+	if ooc.counter == 2 {
+		ooc.counter++
+		return nil, nil
+	}
+
+	return nil, errors.New("device info not found")
+}
+
+// Reboot mocks the Reboot function of Openoltclient.
+func (ooc *MockOpenoltClient) Reboot(ctx context.Context, in *openolt.Empty, opts ...grpc.CallOption) (*openolt.Empty, error) {
+	if ooc.counter == 0 {
+		ooc.counter++
+		return &openolt.Empty{}, nil
+	}
+	return nil, errors.New("reboot failed")
+}
+
+// CollectStatistics mocks the CollectStatistics function of Openoltclient.
+func (ooc *MockOpenoltClient) CollectStatistics(ctx context.Context, in *openolt.Empty, opts ...grpc.CallOption) (*openolt.Empty, error) {
+	return &openolt.Empty{}, nil
+}
+
+// CreateTrafficSchedulers mocks the CreateTrafficSchedulers function of Openoltclient.
+func (ooc *MockOpenoltClient) CreateTrafficSchedulers(ctx context.Context, in *tech_profile.TrafficSchedulers, opts ...grpc.CallOption) (*openolt.Empty, error) {
+	return &openolt.Empty{}, nil
+}
+
+// RemoveTrafficSchedulers mocks the RemoveTrafficSchedulers function of Openoltclient.
+func (ooc *MockOpenoltClient) RemoveTrafficSchedulers(ctx context.Context, in *tech_profile.TrafficSchedulers, opts ...grpc.CallOption) (*openolt.Empty, error) {
+	return &openolt.Empty{}, nil
+}
+
+// CreateTrafficQueues mocks the CreateTrafficQueues function of Openoltclient.
+func (ooc *MockOpenoltClient) CreateTrafficQueues(ctx context.Context, in *tech_profile.TrafficQueues, opts ...grpc.CallOption) (*openolt.Empty, error) {
+	return &openolt.Empty{}, nil
+}
+
+// RemoveTrafficQueues mocks the RemoveTrafficQueues function of Openoltclient.
+func (ooc *MockOpenoltClient) RemoveTrafficQueues(ctx context.Context, in *tech_profile.TrafficQueues, opts ...grpc.CallOption) (*openolt.Empty, error) {
+	return &openolt.Empty{}, nil
+}
+
+// EnableIndication mocks the EnableIndication function of Openoltclient.
+func (ooc *MockOpenoltClient) EnableIndication(ctx context.Context, in *openolt.Empty, opts ...grpc.CallOption) (openolt.Openolt_EnableIndicationClient, error) {
+	if ooc.counter < 2 {
+		ooc.counter++
+		mockInd := &mockOpenoltEnableIndicationClient{0}
+		return mockInd, nil
+	}
+	if ooc.counter == 2 {
+		ooc.counter++
+		return nil, nil
+	}
+	return nil, errors.New("invalid method invocation")
+}
+
+type mockOpenoltEnableIndicationClient struct {
+	count int
+}
+
+func (mock *mockOpenoltEnableIndicationClient) Recv() (*openolt.Indication, error) {
+	if mock.count == 0 {
+		mock.count = mock.count + 1
+		indi := &openolt.Indication{Data: &openolt.Indication_OltInd{OltInd: &openolt.OltIndication{OperState: "Down"}}}
+		return indi, nil
+	}
+	if mock.count == 1 {
+		mock.count = mock.count + 1
+		return nil, errors.New("error, while processing indication")
+	}
+
+	return nil, io.EOF
+}
+
+func (mock *mockOpenoltEnableIndicationClient) Header() (metadata.MD, error) {
+	return nil, nil
+}
+
+func (mock *mockOpenoltEnableIndicationClient) Trailer() metadata.MD {
+	return nil
+}
+
+func (mock *mockOpenoltEnableIndicationClient) CloseSend() error {
+	return nil
+}
+
+func (mock *mockOpenoltEnableIndicationClient) Context() context.Context {
+	return context.Background()
+}
+
+func (mock *mockOpenoltEnableIndicationClient) SendMsg(m interface{}) error {
+	return nil
+}
+
+func (mock *mockOpenoltEnableIndicationClient) RecvMsg(m interface{}) error {
+	return nil
+}